Preferred size for memory block alloc?
-
Hi! in my program I often have to allocate and dellocate buffers for strings. For this, I thought I could avoid memory fragmentation by using an own memory allocation routine which will allocate some more bytes than needed, so many as needed to fill a full block. What is the best size for such a "full" block? Thanks in advance! Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT) -
Hi! in my program I often have to allocate and dellocate buffers for strings. For this, I thought I could avoid memory fragmentation by using an own memory allocation routine which will allocate some more bytes than needed, so many as needed to fill a full block. What is the best size for such a "full" block? Thanks in advance! Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT)If u r using string from STL, it gives facility of reserving memory space. Read more on Function reserve(). This will suffice the need. The chosen One :)
-
If u r using string from STL, it gives facility of reserving memory space. Read more on Function reserve(). This will suffice the need. The chosen One :)
No, I am not using STL. I allocate the memory using 'new' and pointing with a char* to it. Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT) -
No, I am not using STL. I allocate the memory using 'new' and pointing with a char* to it. Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT)Would it be of any benefit to only allocate the memory once and just reuse it?
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
Would it be of any benefit to only allocate the memory once and just reuse it?
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
The maximum size of a string is variable (it could just be one character or 2000 for example). Also there isn't any string number limit (only one string or more than 1000). So I need to allocate them dynamically. Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT) -
The maximum size of a string is variable (it could just be one character or 2000 for example). Also there isn't any string number limit (only one string or more than 1000). So I need to allocate them dynamically. Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT)That's fine. I was just trying to ascertain whether you could minimize the impact on the memory manager. One idea, which is how MFC's CString class works, is to only reallocate when necessary. Something like:
char *pBuffer;
int amount_currently_allocated = 0;while (...)
{
amount_needed = ???;if (amount\_needed > amount\_currently\_allocated) { delete \[\] pBuffer; pBuffer = new char\[amount\_needed\]; amount\_currently\_allocated = amount\_needed; } ...
}
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
That's fine. I was just trying to ascertain whether you could minimize the impact on the memory manager. One idea, which is how MFC's CString class works, is to only reallocate when necessary. Something like:
char *pBuffer;
int amount_currently_allocated = 0;while (...)
{
amount_needed = ???;if (amount\_needed > amount\_currently\_allocated) { delete \[\] pBuffer; pBuffer = new char\[amount\_needed\]; amount\_currently\_allocated = amount\_needed; } ...
}
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
DavidCrow wrote: Five birds are sitting on a fence. Three of them decide to fly off. How many are left? 2 ??? Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT)