> _dos_freemem() in c ~ Online tutorial

_dos_freemem() in c

_dos_freemem() Frees a previously allocated DOS memory block
Declaration:
unsigned _dos_freemem(unsigned segx);
Remarks:
_dos_freemem frees a memory block allocated by a previous call to _dos_allocmem.
segx is the segment address of the block.
Return Value:
On success, both functions return 0 On error,_dos_freemem returns the DOS error code and sets errno to
ENOMEM (Bad memory pointer) freemem returns -1 and sets errno to ENOMEM (Insufficient memory)

Program



 #include <dos.h>
#include <stdio.h>

int main(void)
{
  unsigned int size, segp, err, maxb;
  size = 64; /* (64 x 16) = 1024 bytes */
  err = _dos_allocmem(size, &segp);
  if (err == 0)
    printf("Allocated memory at segment: %x\n", segp);
  else {
    perror("Unable to allocate block");
    printf("Maximum no. of paragraphs available is %u\n", segp);
    return 1;
  }
  if (_dos_setblock(size * 2, segp, &maxb) == 0)
    printf("Expanded memory block at segment: %X\n", segp);
  else {
    perror("Unable to expand block");
    printf("Maximum no. of paragraphs available is %u\n", maxb);
  }
  _dos_freemem(segp);
  return 0;
}

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: