Annotation of os2sdk/demos/examples/suballoc/suballoc.c, revision 1.1.1.1

1.1       root        1: /* This example illustrates the use of the following 286DOS functions:
                      2:  *     DOSSUBSET, DOSSUBALLOC, DOSSUBFREE
                      3:  *
                      4:  * This example allocates a segment <A>, and initialises it for
                      5:  * suballocation. It suballocates a block <B> from <A>, and writes
                      6:  * some value into a word in the block <B>. It then grows segment
                      7:  * <A>, and notifies the suballocator of the new size. It checks
                      8:  * that the value written into block <B> is still there, frees block
                      9:  * <B>, frees segment <A>, and terminates.
                     10:  *
                     11:  * This example program is intended to illustrate the possible functions
                     12:  * rather than do anything useful. It can run as a Family API program.
                     13:  *
                     14:  * Compile as: cl -AL -G0 -Lp suballoc.c
                     15:  *
                     16:  * Copyright (C) Microsoft Corp. 1986
                     17:  */
                     18: 
                     19: #include       <doscalls.h>            /* CP/DOS function declarations      */
                     20: #include       <dos.h>                 /* FP_OFF and FP_SEG macros          */
                     21: 
                     22: /* definitions used in DOSALLOCSEG call */
                     23: #define        SIZEA   16000           /* bytes to allocate */
                     24: #define PRIVATE 0              /* segment will not be shared */
                     25: 
                     26: /* definitions used in DOSSUBSET call */
                     27: #define INIT    1              /* initialise size of subset in a segment*/
                     28: #define INCRSIZE 0             /* increase size of subset in a segment  */
                     29: 
                     30: #define        SUBSIZEA 10000          /* size to suballocate */
                     31: #define SIZER  40000           /* size to reallocate */
                     32: #define BLKSIZE  100           /* size of block within the subset       */
                     33: #define SUBSIZEB 20000         /* size to suballocate after realloc     */
                     34: #define VALUEA   5             /* value to write to first word in block */
                     35: 
                     36: main ()
                     37: {
                     38:        unsigned        Selector,       /* selector for segment allocated    */
                     39:                        BlockOffset,    /* offset to block in segment subset */
                     40:                        *addr;          /*32 bit address to a word in segment*/
                     41: 
                     42:        DOSALLOCSEG (SIZEA, &Selector, PRIVATE); /* allocate a segment */
                     43: 
                     44:        /* subset the segment to size SUBSIZEA ( must be =< SIZEA ) */
                     45:        DOSSUBSET (Selector, INIT, SUBSIZEA);
                     46: 
                     47:        DOSSUBALLOC(Selector, &BlockOffset, BLKSIZE); /* suballocate block B */
                     48: 
                     49:        /* write VALUEA in to first word in block B of the subset */
                     50:        FP_SEG(addr) = Selector;
                     51:        FP_OFF(addr) = BlockOffset;
                     52:        *addr = VALUEA;
                     53:        
                     54:        DOSREALLOCSEG (SIZER, Selector); /* grow the segment to size SIZER */
                     55: 
                     56:        /* subset the segment to size SUBSIZEB where,
                     57:          * (SUBSIZEB > SUBSIZEA) and (SUBSIZEB =< SIZER) */
                     58:        DOSSUBSET(Selector, INCRSIZE, SUBSIZEB);
                     59: 
                     60:        /* first word in block B should still contain VALUEA */
                     61:        if (*addr != VALUEA)
                     62:           printf ("*** error: unexpected value in suballocated block ***\n");
                     63: 
                     64:        DOSSUBFREE (Selector, BlockOffset, BLKSIZE); /* free block B */
                     65: 
                     66:        DOSFREESEG (Selector);          /* free the segment */
                     67: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.