Borland C++ reference

freemem, _dos_freemem

raw OCR

Frees a previously allocated DOS memory block.

Defined in header <dos.h>

Syntax

#include <dos.h>
int freemem(unsigned segx);
unsigned _dos_freemem(unsigned  segx);

Portability

DOSUNIXWindowsANSI CC++ only
■

Remarks

freemem frees a memory block allocated by a previous call to allocmem. _dos_f reemem frees a memory block allocated by a previous call to

_dos_allocmem.segx is the segment address of that block.

Return value

freemem and _dos_freememreturn 0 on success.

In the event of error, freemem returns -1 and sets errno.

In the event of error, _dos_freememreturns the DOS error code and sets

errno. In the event of error, these functions set global variable errno to

ENOMEMInsufficient memory

See also

Example

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

int main(void) /* Example for freemem. */
{
   unsigned int size, segp;
   int Stat;
   size = 64;          /* allocmem requests blocks in 16 byte  chunks,
                          64 of these is 1024 bytes of memory  */
   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);
   freemem(segp);
   return 0;
}
#include <dos.h>
#include <stdio.h>

int main(void)  /* Example for _dos_freemem. */
{
   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

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.

Extraction notes

  • heading `freemem, dos freemem` read as `freemem, _dos_freemem`