• Advertisement

Archived

This topic is now archived and is closed to further replies.

"Weird" memory allocation

This topic is 6747 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Oh yeah - just wanted to make sure you all know that I tested this class throughly in a single thread application. The same exact function, command for command, runs fine when listed in the main source file and incorrectly when used with the DLL - main application combo.

The exact VC++ error message that appears is:

HEAP[GameTest.exe]: Invalid Address specified to RtlValidateHeap( 7a0000, 8d5440 )

7a0000 is the prefix for many of the DLL memory allocations, and 8d5440 is the prefix for many of the main applications memory allocations.

- Splat

[This message has been edited by Splat (edited November 04, 1999).]

Share this post


Link to post
Share on other sites
Advertisement
Try using windows memory management instead of new. I think the function is called GlobalAlloc()?

I'm fairly rusty on mem management in between DLLs and EXEs, but I remember that there's a set of Windows memory allocation functions... maybe they'll do the trick.

Try CoTaskMemAlloc() too, tho IIRC this is more of a COM thing.

Mason McCuskey
Spin Studios www.spin-studios.com

Share this post


Link to post
Share on other sites
it sounds like the dll is allocating space from its memory, so when the exe trys to delete it, it is trying to modify memory that isn't available to it. i think the best way to fix this would be to use pointers

-Delta Rho

Share this post


Link to post
Share on other sites
I figured it out my own way. Not sure if its the nicest, but its good: I just return a reference to a statically declared copy in the DLL function. So the DLL function reads:

String& Func() {
static String myString = "Hi!";
return myString;
}

- Splat

Share this post


Link to post
Share on other sites
Ok, this is pretty weird. I have a lightweight string class called "String" I also have a game engine that runs in a DLL. Now, I want to be able to return from a function in that DLL a copy of a locally held "String" Everything works fine UNTIL the real program (not the DLL) tries to destroy the String class returned by the DLL function.

In effect, it seems that when the String class is created in the DLL, its internal character array ( = new char[...]) is assigned memory from the DLL's local heap space. When the main program tries to destroy that String class, in String's destructor, it reads:

String::~String() {
delete [] data;
}

Pretty simple, except the main program gets basically a memory error because the allocation wasn't made by it.

Now I know I could get away with 100's of tricks, but I really just want to be able to return the String class I don't want to have to pass a String* as a parameter, I don't want to use char arrays. I have now several functions that need to return Strings and more will follow.

It would be nice if someone could help me out here.

- Splat

Share this post


Link to post
Share on other sites

  • Advertisement