-
October 21st, 2008, 07:45 PM
#1
Is it legal to do this?
Allocating memory for an object on one thread and deleting it on another thread? I thought that was ok and that thread share heap space?
Maybe this is not the source of the problem and I have look deeper.
-
October 21st, 2008, 07:53 PM
#2
Re: Is it legal to do this?
Should be safe enough, provided you synchronize properly.
-
October 22nd, 2008, 12:22 AM
#3
Re: Is it legal to do this?
Originally Posted by Lindley
Should be safe enough, provided you synchronize properly.
+1
-
October 23rd, 2008, 12:13 PM
#4
Re: Is it legal to do this?
+1 , but , make sure no matter what, allocaiton and deallocation happen through the same module. Read here:
http://blogs.msdn.com/oldnewthing/ar...15/755966.aspx
http://social.msdn.microsoft.com/For...-7a0969366b1a/
-
October 23rd, 2008, 12:25 PM
#5
Re: Is it legal to do this?
Originally Posted by Rigel
Allocating memory for an object on one thread and deleting it on another thread? I thought that was ok and that thread share heap space?
Maybe this is not the source of the problem and I have look deeper.
Horribly Illegal, and the software police are on their way to arrest you.
Seriously, like the others pointed out, it is generally 100% safe if:
1) You are allocating/releasing the the general heap
2) You have the proper synchronization in place.
The reason I am responsding is that there is also the concepts to TLS [Thread Local Storage] and some environments provide access for a dedicated heap along with this. IF you are using TLS, then the memory refereces are only guaranteed to be valid for the thread in question, and any access (not just a new/delete) is illegal.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|