digitalmars.com                      
Last update Thu Jun 16 21:08:33 2011

page.h


page_calloc

Header
page.h
Prototype
unsigned page_calloc(void __BF *baseptr, unsigned size);
Description
The page_calloc function allocates and clears a block of data from a page heap that was initialized by page_initialize. baseptr points to a page heap initialized by page_initialize. size is the number of bytes to allocate. __BF is defined to be __far for the 16-bit memory models, and __near for the 32-bit memory models.
Return Value
The offset of the allocated data within baseptr. If the allocation fails, 0 is returned.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
page_malloc page_free page_initialize page_realloc
Example
See page_initialize

page_free

Header
page.h
Prototype
int page_free(void __BF *baseptr, unsigned p);
Description
The page_free function frees the memory at offset p in the page heap pointed to by baseptr, which was allocated by page_malloc or page_calloc. __BF is defined to be __far for the 16-bit memory models, and __near for the 32-bit memory models.
Return Value
Returns 0 on success or -1 if an error occurred (for example, if baseptr is bad, or memory is corrupted).
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
page_calloc page_malloc page_initialize
Example
See page_initialize

page_initialize

Header
page.h
Prototype
unsigned page_initialize(void __BF *baseptr, unsigned pagesize);
Description
The page_initialize function creates a page heap for the block of memory pointed to by baseptr which has a size of pagesize. The page_initialize function converts the buffer at baseptr to a page heap. __BF is defined to be __far for the 16-bit memory models, and __near for the 32-bit memory models.

If you use page_initialize to create a page heap, you must use page_functions to manage this heap.

Return Value
The size of the largest allocatable block in baseptr.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
page_calloc page_malloc page_free
Example
#include <stdio.h>
#include <stdlib.h>
#include <page.h>
#include <dos.h>
#include <io.h>

#define HEAPSIZE 0x4000

static char buffer[HEAPSIZE];

void main()
{
 unsigned maxsize, offset;
 char __far *baseptr;
 int __far *fp, i;

 baseptr = MK_FP(getDS(), buffer);
 maxsize = page_initialize(baseptr, HEAPSIZE);
 printf("The maximum allocateable size is
         %04x bytes\n", maxsize);

 offset = page_malloc(baseptr, 0x800);
 if (offset == 0)
 {
    printf("Unable to allocate 0x800 bytes
            with page_malloc()\n");
    exit(EXIT_FAILURE);
 }

 printf("Allocated 0x800 bytes
         successfully\n");

 fp = page_toptr(baseptr, offset);
 for (i = 0; i < 255; i++)
    fp[i] = i;

 printf("fp[50] = %d\n", fp[50]);

 offset = page_realloc(baseptr, offset, 0x1000);
 if (offset == 0)
 {
    printf("Unable to reallocate 0x1000
            bytes\n");
    exit(EXIT_FAILURE);
 }

 printf("Reallocated to 0x1000 bytes\n");

 fp = page_toptr(baseptr, offset);
 printf("fp[50] = %d\n", fp[50]);
 maxsize = page_maxfree(baseptr);
 printf("Maximum free block remaining is %04x
         bytes\n", maxsize);

 if (page_free(baseptr, offset) == -1)
 {
    printf("Unable to free allocated
            block\n");
    exit(EXIT_FAILURE);
 }

 printf("Page freed successfully\n");
}
Output
The maximum allocateable size is 3ff4 bytes
Allocated 0x800 bytes successfully
fp[50] = 50
Reallocated to 0x1000 bytes
fp[50] = 50
Maximum free block remaining is 27f0 bytes
Page freed successfully

page_malloc

Header
page.h
Prototype
unsigned page_malloc(void __BF *baseptr, unsigned size);
Description
The page_malloc function allocates a block of data from a page heap. baseptr points to a page heap that was initialized by page_initialize; size indicates the number of bytes to allocate. __BF is defined to be __far for the 16-bit memory models, and __near for the 32-bit memory models.
Return Value
The offset of the allocated data within baseptr. If the allocation fails, 0 is returned.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
page_calloc page_initialize page_free page_realloc
Example
See page_initialize

page_maxfree

Header
page.h
Prototype
unsigned page_maxfree(void __BF *baseptr);
Description
The page_maxfree function determines size of largest free block in the page heap pointed to by baseptr. This heap must have been initialized with page_initialize. __BF is defined to be __far for the 16-bit memory models, and __near for the 32-bit memory models.
Return Value
The size of the largest free block.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
page_initialize page_free
Example
See page_initialize

page_realloc

Header
page.h
Prototype
unsigned page_realloc(void __BF *baseptr, unsigned p, unsigned nbytes);
Description
The page_realloc function reallocates (changes the size of) a block of memory that was allocated by page_malloc or page_calloc. __BF is defined to be __far for the 16-bit memory models, and __near for the 32-bit memory models.
Return Value
The offset of the reallocated data block from baseptr. If the reallocation fails, 0 is returned.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
page_calloc page_malloc page_initialize page_free
Example
See page_initialize

page_size

Header
page.h
Prototype
unsigned page_size(void __far *baseptr, unsigned p);
Description
The page_size function returns the number of bytes allocated for the block of memory at offset p that was allocated by page_malloc, page_calloc, or page_realloc.
Return Value
The number of bytes in the block.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
page_calloc page_malloc page_initialize page_free page_realloc
Example
See page_initialize

page_toptr

Header
page.h
Prototype
void __BF * __near page_toptr(void __BF *baseptr, unsigned p);
Description
The page_toptr function converts a pointer to a page heap, and an offset into it of p, into a void *pointer. baseptr is a pointer to a heap that was initialized with page_initialize; p is an offset into the heap. __BF is defined to be __far for the 16-bit memory models, and __near for the 32-bit memory models.
Return Value
A far pointer to the position in the page corresponding to offset p.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
page_initialize
Example
See page_initialize
Home | Compiler & Tools | IDDE Reference | STL | Search | Download | Forums