![]() |
|
#1
|
|||
|
|||
reasons why malloc fails?hi,
will someone point me the reasons why a call to malloc fails even if we have enough memory ? |
|
#2
|
|||
|
|||
Re: reasons why malloc fails?Hi prasath,
From what I know, malloc() would only fail if there was insufficient memory or if the size requested was 0. Is malloc() not working properly for you? |
|
#3
|
|||
|
|||
Re: reasons why malloc fails?Quote:
What is "enough memory"? malloc() will fail if it can't allocate enough contiguous memory to satisfy the request. It is possible to malloc and free memory in such a way as to leave the space fragmented so that allocation of a block of a given size is not possible even though the total amount is OK: CPP / C++ / C Code:
My output: Code:
So: Even though 963 megabytes had been deallocated by the time we got to the second allocation loop, there were no blocks large enough to allocate 2 megabytes. When I changed #if 0 to #if 1 (on line 41), here is what I saw: Code:
Now, the blocks are available in loop 2, one megabyte at at time. Regards, Dave Last edited by davekw7x : 05-Apr-2006 at 10:35.
|
Recent GIDBlog
Developing GUIs with wxPython (Part 3) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can't free after malloc | nusstu | C Programming Language | 1 | 20-Apr-2005 09:28 |
| CListCtrl problems - FindItem fails after Sort Items | dotygr | MS Visual C++ / MFC Forum | 0 | 03-Mar-2005 14:23 |
| segfault on malloc (C) | spike666 | C Programming Language | 8 | 15-Jul-2004 14:45 |
| malloc function | Rosmayati | C Programming Language | 5 | 18-May-2004 20:08 |
| Apache Make Fails | beardo | Apache Web Server Forum | 6 | 09-Mar-2004 10:44 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The