Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ alloc(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                                alloc(3C)



        _________________________________________________________________
        alloc                                                    function
        Allocate a block of memory.
        _________________________________________________________________


        Calling Sequence

        char *ptr, *alloc();
        unsigned int size;
        ptr = alloc(size);

        where size is the number of bytes in the block.


        Description

        Use the alloc function to allocate a block of memory.  Since
        hardware representations for pointers to characters differ from
        those of pointers to other data types, use a cast operation to
        convert the result of this function to a pointer of the
        appropriate type.  For example:

        ip = (int *)alloc(n, sizeof(int));

        Any pointer that the alloc function returns is guaranteed to be a
        word-aligned byte pointer.  After the appropriate conversion, it
        can be used as a pointer to any item.

        The include file stdio.h defines the alloc function.


        Returns

        The alloc function returns 0 if no memory was allocated.
        Otherwise, it returns a byte pointer to the allocated memory.


        Related Functions

        See also the alloca, calloc, malloc, and realloc functions.


        Example

        /* Program test for the alloc() function */

        #include <stdio.h>

        char *ptr, *alloc();
        unsigned int size;



        DG/UX 4.00                                                 Page 1
               Licensed material--property of copyright holder(s)





                                                                alloc(3C)



        main(argc, argv)
        int   argc;
        char *argv[];
        {
            size = atou(argv[1]);
            ptr = alloc(size);
            printf("size = %d bytes in the block %o.\n", size, ptr);
        }

        A call to the program test with an argument of 1024 generates the
        following output:

        size = 1024 bytes in the block 34003711770.

        The block address will vary.







































        DG/UX 4.00                                                 Page 2
               Licensed material--property of copyright holder(s)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026