INF:Questions/Answers About the Use of malloc() and _fmalloc()

ID Number: Q12159

3.00 4.00 5.00 5.10 6.00 6.00a 6.00ax 7.00 | 5.00 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

This article contains some common questions about the use of malloc()

and _fmalloc() in a C program written with Microsoft C versions 5.0,

5.1, 6.0, 6.0a, 6.0ax, and C/C++ version 7.0.

More Information:

1. Q. Can malloc() and _fmalloc() be used together without restriction,

for example, using malloc() for the temporary data and _fmalloc()

for the semi-permanent data?

A. Yes, malloc() and _fmalloc() may be used together. They both track

their memory allocation separately and, in fact, you must use two

different functions, free() and _ffree(), respectively, to free the

allocated data.

2. Q. Are there ever any user-visible delays for garbage collection

(compression of string space)?

A. The malloc() functions do not perform any form of garbage

collection. You allocate the space and you decide when it is to be

freed up for later usage. Therefore, there will be no visible or

unexpected time delays during execution.

3. Q. Are there fragmentation risks? In experimenting with _fmalloc(), it

appears that contiguous blocks freed at different times are

automatically consolidated, which should reduce the fragmentation

risk.

A. The _fmalloc() function will consolidate adjacent free blocks. This

reduces the risk of fragmentation problems.

4. Q. Does _fmalloc() ensure that any single assignment is within one

data segment (so assembly move/access routines need not deal with

segment boundaries)?

A. The _fmalloc() function will not allocate across segment

boundaries. Only halloc() (the huge-model memory allocation

routine) can perform this function. Therefore, you are assured that

no one allocation will cross a segment boundary (because it cannot

allocate larger then 64K).

Additional reference words: 5.00 5.10 6.00 6.00a 6.00ax 7.00