Header File Tags: Header File : dos.h Reference
Allocmem() : Allocates DOS memory segment in C [dos.h function]
- Allocates DOS memory segment
- Allocmem use the DOS system call 0×48 .
- It allocate a block of free memory
- It return the segment address of the allocated block.
Declaration :
int allocmem(unsigned size, unsigned *segp);
Parameters :
| | |
| Parameter | | What it does ? | | | |
| size | | The number of 16-byte paragraphs requested | | | |
| segp | | Pointer to a word that will be assigned the segment address of the newly allocated block | | | |
|
---|
If not enough room is available,
- allocmem makes no assignment to the word *segp
- All allocated blocks are paragraph-aligned.
NOTE : malloc can’t coexist with either allocmem or _dos_allocmem.
Return Value :
- On success, allocmem returns -1
- On error, allocmem returns the size of the largest available block and sets both _doserrno and errno to ENOMEM (Not enough memory)
Live Example :
#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;
}