Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ukma!seismo!uunet!microsoft!bobsc From: bobsc@microsoft.UUCP (Bob SCHMIDT) Newsgroups: comp.windows.ms Subject: Re: Does free() Work On Locked Pointers? Keywords: memory management free Message-ID: <72799@microsoft.UUCP> Date: 7 Jun 91 04:55:39 GMT References: <1991Jun3.195715.24598@iti.org> Reply-To: bobsc@microsoft.UUCP (Bob SCHMIDT) Distribution: na Organization: Microsoft Corp., Redmond WA Lines: 36 In article <1991Jun3.195715.24598@iti.org> kam@iti.org (Keith A. McNabb) writes: %% Does anyone know if the the regular C free() function works in Windows %% 3.0 *IF* you've previously allocated memory with LocalAlloc() and then %% obtained the pointer with LocalLock()? %% %% I'm modifying some existing C code, and I don't want to have to keep up %% with handles; it's just a linked list, so the memory blocks are tiny. %% I'm hoping that I can free memory for freed list elements with the %% regular free function, passing it the pointer . LocalFree() requires a %% handle. %% %% uSoft SDK documentation says only: "You can use ... malloc, calloc, %% realloc, and free, but [...] you may get unexpected results." %% %% ?????????? %% %% Keith McNabb %% kam@iti.org There is a better way... The Windows API 'LocalHandle' will convert a LocalLocked pointer to its corresponding local handle. Thus, you can create your own 'Free' which is essentially HANDLE Free(void _near *Pointer) { return LocalFree(LocalHandle(Pointer)); } This code is naive and has no error checking, but does show the idea. -- -- Bob Schmidt bobsc@microsoft.UUCP -- -- Bellevue WA USA Windows SDK Support -- Sydney NSW Australia Developer Support (after 1 Oct)