Re: malloc and realloc
- From: "matevzb" <matevzb@xxxxxxxxx>
- Date: 27 Jan 2007 13:03:41 -0800
On Jan 27, 9:16 pm, "Malcolm McLean" <regniz...@xxxxxxxxxxxxxx> wrote:
"Richard Heathfield" <r...@xxxxxxxxxxxxxxx> wrote in messageI'll have to ask for chapter&verse on this one. If you're referring to
The absolute limit for any one call is (size_t)-1 bytes - i.e. the largestActually Windows guarantees that allocations of under 8K or something like
value that can be stored in a size_t, because that's the largest value you
can pass to malloc. But you should not be surprised if implementations do
not allow you to allocate this much. ALWAYS check the result of malloc to
determine whether the call succeeded before trying to use the space you
requested.
that will succeed, unless the program is responding to a request to shut
down due to lack of memory, in which case 64K of allocation or so is
guaranteed, but not an infinite supply of 64K chunks.
Windows malloc(), the manual explicitly states "Always check the
return from malloc, even if the amount of memory requested is small".
Furthermore, malloc() uses HeapAlloc() to get the memory: "Memory
allocated by HeapAlloc is not movable. Because the memory is not
movable, the heap can become fragmented". In theory, it could become
so fragmented, that you wouldn't be able to get 8K.
So on a modern operating system you don't need to check small mallocs. YouThe conclusion is drawn from Windows, can you be sure this should
do if code is to be completley portable, of course.
apply to all other systems as well?
--
WYCIWYG - what you C is what you get
.
- References:
- malloc and realloc
- From: ravi . cs . 2001
- Re: malloc and realloc
- From: Richard Heathfield
- Re: malloc and realloc
- From: Malcolm McLean
- malloc and realloc
- Prev by Date: Re: Best Multi-Platform Way to Define Standard Types Such as UINT32
- Next by Date: Re: malloc and realloc
- Previous by thread: Re: malloc and realloc
- Next by thread: Re: malloc and realloc
- Index(es):
Relevant Pages
|