2 * CRTDLL memory functions
4 * Copyright 1996,1998 Marcus Meissner
5 * Copyright 1996 Jukka Iivonen
6 * Copyright 1997,2000 Uwe Bonnes
7 * Copyright 2000 Jon Griffiths
9 * Implementation Notes:
16 DEFAULT_DEBUG_CHANNEL(crtdll);
18 static new_handler_type new_handler;
21 /*********************************************************************
26 LPVOID __cdecl CRTDLL_new(DWORD size)
29 if(!(result = HeapAlloc(GetProcessHeap(),0,size)) && new_handler)
35 /*********************************************************************
38 * Free memory created with new.
40 VOID __cdecl CRTDLL_delete(LPVOID ptr)
42 HeapFree(GetProcessHeap(),0,ptr);
46 /*********************************************************************
47 * set_new_handler(CRTDLL.003)
49 new_handler_type __cdecl CRTDLL_set_new_handler(new_handler_type func)
51 new_handler_type old_handler = new_handler;
57 /*********************************************************************
58 * _expand (CRTDLL.088)
60 * Increase the size of a block of memory allocated with malloc()
63 LPVOID __cdecl CRTDLL__expand(LPVOID ptr, INT size)
65 return HeapReAlloc( GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY, ptr, size );
69 /*********************************************************************
72 * Return the actual used size of an allocated block of memory.
75 LONG __cdecl CRTDLL__msize(LPVOID mem)
77 LONG size = HeapSize(GetProcessHeap(),0,mem);
80 WARN(":Probably called with non wine-allocated memory, ret = -1\n");
81 /* At least the win98/nt crtdlls also return -1 in this case */
87 /*********************************************************************
90 * Allocate memory from the heap and initialise it to zero.
92 LPVOID __cdecl CRTDLL_calloc(DWORD size, DWORD count)
94 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
98 /*********************************************************************
101 * Free a block of memory allocated with malloc()
103 VOID __cdecl CRTDLL_free(LPVOID ptr)
105 HeapFree(GetProcessHeap(),0,ptr);
109 /*********************************************************************
110 * malloc (CRTDLL.424)
112 * Alocate memory from the heap.
114 LPVOID __cdecl CRTDLL_malloc(DWORD size)
116 LPVOID ret = HeapAlloc(GetProcessHeap(),0,size);
118 __CRTDLL__set_errno(GetLastError());
123 /*********************************************************************
124 * realloc (CRTDLL.444)
126 * Resize a block of memory allocated with malloc() or realloc().
128 LPVOID __cdecl CRTDLL_realloc( VOID *ptr, DWORD size )
130 return HeapReAlloc( GetProcessHeap(), 0, ptr, size );