memory address

hello,
im trying to simulate the memory management so i want first to allocate x bytes and then working inside that space only..
how can i know the address of my object in the memory?

thanks

[201 byte] By [ppl1] at [2008-1-23]
# 1
You can get the address of an object by using the address-of operator (&Wink, however this can only be used in an unsafe context or you could use GCHandle and retrieve the address by using the GCHandle.AddrOfPinnedObject method.

However you need to be careful. These are normally not needed in most applications. What exactly are you trying to do? Simulate an OutOfMemoryException or something?

DavidM.Kean at 2007-8-21 > top of Msdn Tech,Visual C#,Visual C# Language...
# 2
well..im trying to simulate a memory management, but i need to do it without the "unsafe code" ,also to simulate outOfMemoryException
i just thouth that i dont need to know the address because i have the handle and the size .
what kind of a collection is the right one to use? hashTable ?Lists?
thanks
ppl1 at 2007-8-21 > top of Msdn Tech,Visual C#,Visual C# Language...
# 3
I'm still confused. What do you mean by 'im trying to simulate a memory management'?

Also I'm not sure I understand what you are trying to do, so I can't answer the collection answer. What are you going to store in the collection?

DavidM.Kean at 2007-8-21 > top of Msdn Tech,Visual C#,Visual C# Language...
# 4
i created a class where im saving an identifier and the size (thats the block in the memory),
alse im allocating x bytes and its supposed to be the memory.
not sure its understandable now..anyway thanks for help
ppl1 at 2007-8-21 > top of Msdn Tech,Visual C#,Visual C# Language...
# 5
I'm sorry I still don't understand what you are trying to achieve and therefore I can't help you.

Rather than telling me what you are trying do within code, tell me what you want to achieve in a broader scope.

How are you allocating the memory? In .NET you typically do not need to worry about allocating memory, it is done under hood when you create an instance of an object.

DavidM.Kean at 2007-8-21 > top of Msdn Tech,Visual C#,Visual C# Language...
# 6
i dont know what else to say so nevermind..thanks again for the help
ppl1 at 2007-8-21 > top of Msdn Tech,Visual C#,Visual C# Language...
# 7
Hi,

Objects created in C# (Assuming you are not using Unsafe Code) are placed in the Managed Heap, It has no permanent memory address coz it is constantly being moved by the GC(Garbage Collector)...
cheers,
Paul June A. Domag

PaulDomag at 2007-8-21 > top of Msdn Tech,Visual C#,Visual C# Language...