From: grundmann Newsgroups: comp.os.msdos.djgpp Subject: Re: Memory Problem Date: Mon, 27 Jul 1998 18:32:10 +0200 Organization: Heinrich Heine Universitaet Duesseldorf Lines: 70 Message-ID: <35BCAB8A.9FC7C98D@uni-duesseldorf.de> References: NNTP-Posting-Host: qexafs1.anphy.uni-duesseldorf.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Eli Zaretskii wrote: > On Fri, 24 Jul 1998, grundmann wrote: > > > I am writing an application that needs lots of memory > > How can i determin the amount of memory which i can allocate with malloc > > without getting a NULL pointer ? > > The easiest way is to call `_go32_dpmi_remaining_virtual_memory' at > the very beginning of your program. This avoids the problems with the > internal free memory pool maintained by malloc/free, whose size you > cannot know (at the beginning of the program, this pool has a > negligible size). > > Beware: some DPMI servers won't allow you to allocate all of the free > memory in a single large chunk. See the FAQ for details. > > > Do i have to configure CWSDPMI sepcial to use 64 MB Ram ( or 96 MB > > No. But you may need to configure your system to allow CWSDPMI access > to more than 64MB, since some memory managers limit the memory they > make available to programs. Ok then please look at that code : fprintf(error_file,"There is still %ld bytes physical memory\n",_go32_dpmi_remaining_physical_memory()); fprintf(error_file,"There is still %ld bytes virtual memory\n",_go32_dpmdi_remaining_virtual_memory()); buffer_size=_go32_dpmi_remaining_virtual_memory()/3*2; fprintf(error_file,"The Buffer size is:%d\n",buffer_size); sample_buffer=(short *)SicherAlloc(buffer_size); fprintf(error_file,"First chunk allocated\n"); fprintf(error_file,"There is still %ld bytes physical memory\n",_go32_dpmi_remaining_physical_memory()); fprintf(error_file,"There is still %ld bytes virtual memory\n",_go32_dpmi_remaining_virtual_memory()); void *SicherAlloc(size_t size){ void *pointer; if((int)(pointer=malloc(size))) return pointer; fprintf(error_file,"Error Allocating %ld bytes.\n",size); exit(1); } And then look at the output which is given in the error_file : There is still 62693376 bytes physical memory There is still 69185536 bytes virtual memory Die Buffer size ist:46123690 First chunk allocated There is still 62689280 bytes physical memory There is still 2011136 bytes virtual memory This is done under dos with CWSDPMI . Does malloc has such an overhead ? There are about 20 Megabytes of Memory missing ! The second thing is that i only want physical memory cause i sample from a AD Card very quick and it is possible that i loose data when i use swapped mem. I tried to move the data to disk ( with normal open and write functions ) but it didn't work . I got an buffer overflow in the sample buffer of the AD Card . I move 8 Kilobyte blocks from card to memory and then tried to move them to disk but without success .