Click to See Complete Forum and Search --> : Buffer Size


Kohinoor24
October 11th, 2002, 02:21 AM
Hi,
Iam Having a Buffer & I dont know how many bytes Iam going to write to the buffer.
Right Now Iam giving a Buffer size of 1000000.
What is the max: size I can give & What are the things it depends on.

Thanks

cup
October 11th, 2002, 03:46 AM
You could have a routine which keeps track of how many bytes it has written to the buffer and realloc as required. It doesn't matter what the max is then.

Basically the max is the size of your virtual memory/swap. It does mean that you could run out of swap if other programs are running.

JMS
October 11th, 2002, 10:21 AM
>> Right Now Iam giving a Buffer size of 1000000.
>> What is the max size I can give & What are the things it
>> depends on.

The max size is OS dependent. Suffice it to say that you could probable allocate enough memory in Microsofts OS to get your self into trouble... UNIX will also let you allocate a large block, only in Unix your program will suffer performace loss rather than slowing down the entire OS.

A better solution than allocating a huge block of memory would be to allocate a series of smaller blocks kept in a linked list. Then you could just roll over to a new node as you needed new memory. Likewise the OS is smart enough to swap out nodes which are not being used so you're not leaving a huge unuseable tombstone in you're physical memory for the OS to work around.

I believe in Unix or Windows each process has a two gig addressable address space availible to it. How much of this memory you could actually allocate at any one time is dependent upon availible physical memory, free hard disk (swap) space, and what is the memory utilizations of other programs which you've got running.

Waldo2k2
October 11th, 2002, 10:44 AM
I've noticed that windows 9x handles bit sizes of 16, 32,64,128,256, 512, etc. very well...sometimes i've had it puke on sizes like 10000...plus normal units like that are much better because it doesn't leave sectors partly full. Just read in x amount of bytes at a time...just make sure to clean your pointers before you keep writing to them (you don't want overruns).

vinodp
October 12th, 2002, 06:17 PM
I think its bad idea to write ur own routine to handle all memory allocating, reallocating & deallocating.
Better soln is used STL container (may be vector)which going to do task for u.

Vinod