2 * msvcrt.dll heap functions
4 * Copyright 2000 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Note: Win32 heap operations are MT safe. We only lock the new
21 * handler and non atomic heap operations
29 /* round to 16 bytes + alloc at minimum 16 bytes */
30 #define ROUND_SIZE(size) (max(16, ROUND_UP(size, 16)))
37 void* malloc(size_t _size
)
39 size_t nSize
= ROUND_SIZE(_size
);
44 return HeapAlloc(hHeap
, 0, nSize
);
52 HeapFree(hHeap
,0,_ptr
);
58 void* calloc(size_t _nmemb
, size_t _size
)
60 size_t nSize
= _nmemb
* _size
;
61 size_t cSize
= ROUND_SIZE(nSize
);
63 if ( (_nmemb
> ((size_t)-1 / _size
)) || (cSize
<nSize
))
66 return HeapAlloc(hHeap
, HEAP_ZERO_MEMORY
, cSize
);
72 void* realloc(void* _ptr
, size_t _size
)
76 if (( _size
== 0) && (_ptr
!=NULL
))
79 nSize
= ROUND_SIZE(_size
);
84 if (!_ptr
) return malloc(_size
);
85 if (_size
) return HeapReAlloc(hHeap
, 0, _ptr
, nSize
);
93 void* _expand(void* _ptr
, size_t _size
)
97 nSize
= ROUND_SIZE(_size
);
102 return HeapReAlloc(hHeap
, HEAP_REALLOC_IN_PLACE_ONLY
, _ptr
, nSize
);
108 size_t _msize(void* _ptr
)
110 return HeapSize(hHeap
, 0, _ptr
);
118 if (!HeapValidate(hHeap
, 0, NULL
))
128 if (!HeapCompact(hHeap
, 0))
136 int _heapset(unsigned int unFill
)
138 if (_heapchk() == -1)
147 int _heapwalk(struct _heapinfo
* entry
)