Allocates DOS memory segment
Declaration:
int allocmem(unsigned size, unsigned *segp);
Remarks:
allocmem and _dos_allocmem use the DOS system call 0x48 to allocate a block
of free memory and return the segment address of the allocated block.
If not enough room is available, allocmem makes no assignment to the word *segp
_dos_allocmem stores the size of the largest
available block in the word *segp.
All allocated blocks are paragraph-aligned.
Return Value:
On success,
allocmem returns -1
_dos_allocmem returns 0
On error,
allocmem returns the size of the largest available block and
sets both _doserrno and errno to ENOMEM (Not enough memory)
_dos_allocmem returns the DOS error code and sets errno to ENOMEM
program
#include <dos.h>
#include <alloc.h>
#include <stdio.h>
int main(void)
{
unsigned int size, segp;
int stat;
size = 64; /* (64 x 16) = 1024 bytes */
stat = allocmem(size, &segp);
if (stat == -1)
printf("Allocated memory at segment: %x\n", segp);
else
printf("Failed: maximum number of paragraphs available is %u\n", stat);
return 0;
}
0 comments:
Post a Comment