Top.Mail.Ru
The C++ Community's Journal -- Day
? ?
The C++ Community's Journal -- Day [entries|friends|calendar]
The C++ Community

[ userinfo | livejournal userinfo ]
[ calendar | livejournal calendar ]

Very interesting situation for realloc [17 Jul 2008|05:39am]
I have pointer to small struct. For example:

struct a
{
unsignred long number;
char *name;
} *pa;

where *pa allocated with realloc:
pa = realloc(pa, sizeof(a)*Num_a);

and Num_a can be very great and always increasing. And i have interesting situation: for any realloc call system allocate block of memory (above than current block because block greater than current can be only above) and copy old block. then system freeing old block. For new realloc call memory which lower current block is too small for allocate for new size. And system allocate block above. All works while allocated memory less than free memory/2 and address of allocated block below memory/2. When it's condition is false (size of need memory greater than memory/2) i have exception in realloc or API functions. And have enough memory below current allocation.

What you can advise? linked list will be very slow for big number of records :(
19 comments|post comment

navigation
[ viewing | July 17th, 2008 ]
[ go | previous day|next day ]
Image