Old 17th September 2008, 14:55   #1
bruder_s
Junior Member
 
Join Date: Sep 2001
Posts: 34
Best way to handle memory access?

Hi,

currently I'm running into some trouble and it seems that memory allocations are the cause (at some point, realloc fails).
I've created a DLL based on the ml_http sample in the SDK and I'm basically reading a small text file into a wchar_t* memory block. Reading the file 10000 times at the Init()-stage does work, but reading the same file later, while winamp is playing, will crash trying to realloc +1 wchar_t.

Since I have not very much experience here, could it be that some other plugin or even winamp is writing to the same memory area as my plugin or is this not possible at all?

Can you hint me in the right direction how to debug this one (VC2008)?
May it help to use HeapAlloc-functions instead, and if so, should I create my own heap (CreateHeap) or use winamp's (GetProcessHeap) (if that's possible at all)?
Any other suggestions?

Regards, Christian
bruder_s is offline   Reply With Quote
Old 17th September 2008, 16:33   #2
griffins_Grader
Senior Member
 
Join Date: Aug 2008
Posts: 114
post portion of your code here.
griffins_Grader is offline   Reply With Quote
Old 17th September 2008, 18:39   #3
bruder_s
Junior Member
 
Join Date: Sep 2001
Posts: 34
I guess I found the error.

But my questions remain:

Is it recommendable to use stuff like HeapCreate/HeapAlloc instead of malloc?
Can winamp or other plugins corrupt the memory area of my plugin (I guess winamp can, other DLLs can't or shouldn't) - are there differences XP/Vista?
Any hints how to debug stuff like this better (this one was just luck while looking at the code I guess)?

Regards, Christian
bruder_s is offline   Reply With Quote
Old 17th September 2008, 18:45   #4
griffins_Grader
Senior Member
 
Join Date: Aug 2008
Posts: 114
Have you looked at LocalAlloc?
griffins_Grader is offline   Reply With Quote
Old 17th September 2008, 18:50   #5
bruder_s
Junior Member
 
Join Date: Sep 2001
Posts: 34
Hm yes, now ;-)

But frankly, "New applications should use the heap functions" and "Windows memory management does not provide a separate local heap and global heap. Therefore, the LocalAlloc and GlobalAlloc functions are essentially the same." scare me of.

If a winamp developer would say that we should use this function to allocate memory in a winamp plugin, it would be another thing, though...

Regards

Edit: The *Lock functions sound interesting though...
bruder_s is offline   Reply With Quote
Old 17th September 2008, 18:58   #6
griffins_Grader
Senior Member
 
Join Date: Aug 2008
Posts: 114
Fact: I get weird result when I use anything other than LocalAlloc to allocate block of memory in dll. You can attach your module to the IDE and see what exactly the cause is.
griffins_Grader is offline   Reply With Quote
Old 17th September 2008, 19:02   #7
bruder_s
Junior Member
 
Join Date: Sep 2001
Posts: 34
OK, thanks for the info, but I never had 'big' trouble with memory handling in the past. Just thought maybe winamp has changed some things (it has been a while since I last worked on the plugin).

I wanted to try to encapsulate all my malloc/realloc/free calls anyway, so if I run into problems next time, I can tryout some stuff.
bruder_s is offline   Reply With Quote
Old 18th September 2008, 12:41   #8
DrO
 
Join Date: Sep 2003
Posts: 27,873
different people seem to see different things depending on whatever else is in their winamp install, OS, etc.

basically go with the memory handling that you're happiest using and don't have issues with. most plugins i've seen use the Local/GlobalAlloc() or malloc() variants though this is the odd usage of the Heap*() apis (though you can see why people don't use them at times since it involves a little bit more coding at times).

as far as Winamp, there's reference to GlobalFree() in wa_ipc.h for the ipc_get_extlist api but that is the only header api reference. i cannot remember what the sdk examples use but as said above, use whatever you think is the best for what you're needing to do.

-daz
DrO is offline   Reply With Quote
Old 18th September 2008, 13:07   #9
bruder_s
Junior Member
 
Join Date: Sep 2001
Posts: 34
Thanks for the info.

Nice to hear this, I guess I'm staying with malloc for now...
bruder_s is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > Winamp Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump