Thread: Array deallocation

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    7

    Unhappy Array deallocation

    Hi!!!

    I am really in a mess now. I have written this compiler which uses huge datastructures everythin in the form of array. by the time i realised that pointer wud have been a better option, i had written about 75% of the code. now the problem is, there is a serious memory overflow. i am not able to deallocate array from the memory. infact i can do that by setting the structures each to null. but well there are some 10-15 structures and i'll have to write seperate functions for each of these and more worser the each structures is quite complicated.
    is there any way i can deallocate memory from the array, like using free. i used free(), but i guess its more for pointers and my os(dos) crashes whenever i used free(array). wat is the most easier and
    hopefully the best way to deallocate memory from "an array"?

    thnx a lot in advance,
    R Karthick

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    You can not deallocate an array. Function free() must be used in combination with some dynamic memory allocation function like malloc(). You can't free() an array. I would recommend using dynamic memory allocation and replace this by the arrays. Isn't there an easier way to adapt your code? If the interfaces to the structures are seperated from their implementation, then you could just change the implementation without adapting other parts of the code.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You have to be more specific. You should always free() everything that you malloc():ed, and free it in reverse order if it is nestled (ie if you allocate memory for an array of pointers, which in turn will allocate more memory).
    You should also set the pointers to NULL after freeing them.

    . i am not able to deallocate array from the memory. infact i can do that by setting the structures each to null
    You don't deallocate memory when setting the pointer to NULL. Use free().
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    It means that you cannot dynamically deallocate a memory that is dynamically allocated.
    none...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM