Microsoft KB Archive/106396

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

_vmalloc() Allocation Limited to 64K

Q106396

7.00 | 1.00 1.50 MS-DOS | WINDOWS kbprg kbcode ---------------------------------------------------------------------- The information in this article applies to: - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0 and 1.5 ---------------------------------------------------------------------- SUMMARY ======= The _vmalloc() function fails when attempting to allocate a memory block greater than 64K minus 6 bytes. Even though the type of the block size parameter passed to _vmalloc() is an unsigned long, the maximum block that can be allocated with a single call to _vmalloc() is slightly less than 64K. MORE INFORMATION ================ The _vmalloc() function will return _VM_NULL if the block size requested is 65531 bytes or larger. The Virtual Memory Manager (VMM) is only able to associate a single 64K block of memory with a virtual memory handle. The extra 6 bytes are used to store internal information about the memory block. The block size limitation is due to the way the Virtual Memory Manager uses conventional memory to swap in virtual memory blocks. When an application allocates a block of virtual memory, the memory must be brought down to a swap area in conventional memory. This is similar to the page frame implemented by expanded memory. The swap area in conventional memory that the Virtual Memory Manager uses is limited to 64K bytes. The sample code below fails on the call to _vmalloc() because the size requested exceeds the 64K minus 6 byte limit. Sample Code ----------- / * Compile options needed: none */ #include #include void main( void ) { _vmhnd_t handle; unsigned long block_size; unsigned long mem_size; if ( !_vheapinit( 0, _VM_ALLDOS, _VM_XMS | _VM_EMS ) ) { printf( "Could not initialize virtual memory manager.\n" ); exit( -1 ); } /* The following allocation request will fail. */ if ( (handle = _vmalloc( 65531L )) == _VM_NULL ) { _vheapterm(); printf("Allocation failed!"); exit( -1 ); } _vfree( handle ); _vheapterm(); } Additional reference words: kbinf 7.00 1.00 1.50 _vmalloc _vrealloc KBCategory: kbprg kbcode KBSubcategory: VirtualMem

Keywords : kb16bitonly
Issue type :
Technology : kbVCsearch kbAudDeveloper kbPTProdChange kbvc150 kbvc100 kbZNotKeyword3 kbCVC700DOS


Last Reviewed: May 6, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.