1) Tried to debug a program on Windows XP, which allocates 2 memorys and it most times returns the same address... (tested with 4.02, 4.20 and 4.30)... and after little time it crashes on the second LocalAlloc (Invalid memory access. (write error at address ...).
Strangest of all, when running a compiled version in debugger (olly debug), it works fine, or when running on Windows 98
2) On another program (currently discontinued), sometimes the program never returns from a LocalAlloc (Windows 98, not sure about PureBasic version)
Note: Typically i use LocalAlloc(0, size) (= LMEM_FIXED) only
Problems with LocalAlloc
- Controller
- User
- Posts: 28
- Joined: Thu Jul 22, 2004 5:26 am
- Location: Germany
- Contact:
Probably this: http://www.purebasic.fr/blog/?p=55
- Controller
- User
- Posts: 28
- Joined: Thu Jul 22, 2004 5:26 am
- Location: Germany
- Contact:
thx, but seems the problem is quite simple and another reason for me to dislike Windows XP; Problem was I LocalFree-ed one memory twice, like this simple example:
Repeat
xLong1 = LocalAlloc_(0, 200)
xLong2 = LocalAlloc_(0, 200)
If xLong2 = xLong1
Debug "Doubled!"
EndIf
LocalFree_(xLong1)
LocalFree_(xLong1) ; (Should be xLong2)
ForEver
Repeat
xLong1 = LocalAlloc_(0, 200)
xLong2 = LocalAlloc_(0, 200)
If xLong2 = xLong1
Debug "Doubled!"
EndIf
LocalFree_(xLong1)
LocalFree_(xLong1) ; (Should be xLong2)
ForEver
-
- Enthusiast
- Posts: 480
- Joined: Thu Jul 27, 2006 4:06 am
why are you using the api, can't you use the pb functions? that'll make your application cross-platform. internally it'll use a heap in windows, which is proffered to globalalloc or localalloc anyway.
also, try handling your memory with a little of thought, always null your pointers and check if they aren't null before trying to free anything.
also, try handling your memory with a little of thought, always null your pointers and check if they aren't null before trying to free anything.


- Controller
- User
- Posts: 28
- Joined: Thu Jul 22, 2004 5:26 am
- Location: Germany
- Contact:
1) Cross-plattform is not needed (I primaly develop on Windows 98 and got enough probs with Windows XP incompatibility and dynamic unicode support). Esp. this project here uses API not integrated in PureBasic (Resources, waveIn) and some core parts are already written in assembly.
2) LocalAlloc may not be the best methode, but it's easy to use. I use it for dynamic memory allocation mostly.
3) I typically null pointers if it's needed, so this should not occur. Knowing this behaviour on Windows XP, I'll take even more care when writing the freeing stuff. As LocalFree() returns 0 (SUCCESS) both times on Windows XP, I'm glad I'm using Windows 98 because I can trap this errors here.
2) LocalAlloc may not be the best methode, but it's easy to use. I use it for dynamic memory allocation mostly.
3) I typically null pointers if it's needed, so this should not occur. Knowing this behaviour on Windows XP, I'll take even more care when writing the freeing stuff. As LocalFree() returns 0 (SUCCESS) both times on Windows XP, I'm glad I'm using Windows 98 because I can trap this errors here.
-
- Enthusiast
- Posts: 480
- Joined: Thu Jul 27, 2006 4:06 am
-
- Enthusiast
- Posts: 767
- Joined: Sat Jan 24, 2004 6:56 pm
Using PB functions, it would have been spoted by the runtime debugger:
Code: Select all
Repeat
xLong1 = AllocateMemory(200)
xLong2 = AllocateMemory(200)
If xLong2 = xLong1
Debug "Doubled!"
EndIf
FreeMemory(xLong1)
FreeMemory(xLong1) ; (Should be xLong2)
ForEver
- Controller
- User
- Posts: 28
- Joined: Thu Jul 22, 2004 5:26 am
- Location: Germany
- Contact: