Subj : Re: largest memory block To : borland.public.cpp.borlandcpp From : Mohsen Date : Tue Mar 22 2005 03:30 am maeder@glue.ch (Thomas Maeder [TeamB]) wrote: >"Mohsen" writes: > >> How can I find out how much memory is avalable, > >I'm sure that there are APIs that claim to provide that information, >but ... > > >> and how I can allocate that amount of memory? > >... you can't do this. In general, the amount of memory available in >the allocation isn't the same as the one you have just queried, >because other tasks also allocate (and release) memory. > >IMHO, this means that the above mentioned APIs are rather useless. > > >On operating systems where memory allocation is reliable (I think >Windows are among them), the simplest approach is to try to allocate a >certain amount of memory. If that fails, try to allocate less or >report failure. > > >On other operating systems, memory allocatino is not reliable (Linux >is among these). A memory allocation can seem to succeed, but using >that memory will then terminate the program. The only reliable >strategy I can think of is to allocate the memory at program start and >try to use it immediately to see if that works. Thanks for your help. If I want to specifically talk about my problem, I should say that using containers such as STL's vector or BIDS's(old) TArray have the drawback that when they are reallocating they double the memory and in that sense they are inefficient for tasks that require speed and memory. The only solution is to set the amount of memory to predefined value which in fact reduces the number of reallocations. That value is not clear for me. I have also thought of a specific value and then reduce it if that amount is not available, but this also limits the usability and reduces the efficiency when for example running the program on a computer with 1GB RAM relative to another computer with 128MB RAM. Mohsen .