Thread: when to allocate memory

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218

    Smile when to allocate memory

    Hi everybody, can any one help me with this i much appreciate it.

    I have at times this problem of not being sure if i have to allocate
    memory space for a certain var(usually strings or blocks of memory and at times had become a game of guessing) so i will put these in list below
    please if you can tell me in which cases i need to allocate memory either with mallock or calloc.and inwhich i dont need.

    case # 1 =Lets say we have a char string nonconstant that we dont know the lenght of it like a directory environmental block or a
    structure member

    case #2 = a fixed const char string like"hello everybody"

    now which of the variables listed below need to allocate memory to point and be able to hold the data for the cases above

    Code:
    BYTE    *ptobyte
    
    PTSTR    *ptstr
    
    char     *pchar
    
    BUFFER   pbuffer
    and couple of more types that i forgot and u can tell if u know of.

    Now i need to know which one of the above variables need to allocate mem to hold the data for the 2 cases i mentioned earlier?

    there are cases that i forget to allocate mem and the program works fine may be the compiler is doing it for me.

    thank you in advance
    Last edited by SAMSAM; 01-22-2003 at 11:24 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 06:36 PM
  2. Memory Leak Help
    By (TNT) in forum Windows Programming
    Replies: 3
    Last Post: 06-19-2006, 11:22 AM
  3. Allocate a big dynamic memory location
    By vnrabbit in forum C Programming
    Replies: 11
    Last Post: 10-09-2002, 08:02 AM
  4. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM
  5. Error when freeing memory
    By foniks munkee in forum C Programming
    Replies: 9
    Last Post: 03-01-2002, 08:28 PM