Microsoft KB Archive/63003

= Basic 7.00 SETMEM Example Uses malloc/free; Should Be halloc =

Article ID: 63003

Article Last Modified on 10/20/2003

-

APPLIES TO


 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q63003



SUMMARY
The example for the SETMEM function on Page 333 of the &quot;Microsoft Basic 7.0: Language Reference&quot; 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).

Keywords: KB63003

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.