Basic 7.00 SETMEM Example Uses malloc/free; Should Be halloc (63003)



The information in this article applies to:

  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1

This article was previously published under Q63003

SUMMARY

The example for the SETMEM() function on Page 333 of the "Microsoft Basic 7.0: Language Reference" manual (for 7.00 and 7.10) incorrectly uses the C malloc() and free() functions to allocate and free memory instead of the correct halloc() and hfree() functions.

This information applies to Microsoft Basic Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS.

MORE INFORMATION

To be able to free memory for Basic to reallocate, it is necessary to use the heap functions [halloc() and hfree()] instead of normal memory allocation functions. If SETMEM() is used to reallocate memory for Basic after using free(), no memory will be reallocated. With hfree(), the memory will be returned for use with Basic.

For more information on using SETMEM() with C functions, query on the following keywords:

SETMEM and halloc

Code Example

The corrected C code for the SETMEM() example is as follows:
void far cfunc(bytes)
int bytes;
{
    char *halloc();
    char *workspace;

    /* Allocate working memory (halloc) using amount Basic freed. */ 
    workspace=halloc((unsigned) bytes, 1);

    /* Working space would be used here. */ 

    /* Free memory (hfree) before returning to Basic */ 
    hfree(workspace);
}
				
NOTE: The C code must be compiled using the huge model (/AH).

Modification Type:MajorLast Reviewed:10/20/2003
Keywords:KB63003