468,768 Members | 1,579 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,768 developers. It's quick & easy.

Large object heap...

Hi!

If the array is allocated from the large object heap
does that mean that it does not have to be pinned down
when passed to unmanaged code?

Is the limit of 1000 elements as the switching point
between small and large object heap
fixed and something that we can depend upon?

Thanks!
Atmapuri
Sep 7 '06 #1
5 2297
Hello Atmapuri,

AIf the array is allocated from the large object heap does that mean
Athat it does not have to be pinned down when passed to unmanaged
Acode?

LOH is not compacted, but this doesn't means (as guys from GC team say) that
you shouldn't pin you object, because realization could be change at any time

AIs the limit of 1000 elements as the switching point
Abetween small and large object heap
Afixed and something that we can depend upon?

what do u mean by "small object heap". Whether the object is in LOH or not
depends on it side. Everything is more 85000 bytes is in LOH

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Sep 7 '06 #2
>If the array is allocated from the large object heap
>does that mean that it does not have to be pinned down
when passed to unmanaged code?
Why are you asking, do you perform the pinning manually? The runtime
marshaler will do the right thing for you so don't worry about it.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 7 '06 #3

"Atmapuri" <di*@community.nospamwrote in message
news:ee**************@TK2MSFTNGP02.phx.gbl...
| Hi!
|
| If the array is allocated from the large object heap
| does that mean that it does not have to be pinned down
| when passed to unmanaged code?
|
| Is the limit of 1000 elements as the switching point
| between small and large object heap
| fixed and something that we can depend upon?
|
| Thanks!
| Atmapuri
|
|

When using PInvoke interop pinning is not something you need to take care
of, it's done automagically by the interop layer, nor should you really care
where your objects live, this is an implementation detail and can change
with every release.

Willy.
Sep 7 '06 #4
Hi!
Why are you asking, do you perform the pinning manually? The runtime
marshaler will do the right thing for you so don't worry about it.
Really? I noticed from other replies that this is suppose to work,
but sounds strange:

So, if I write:

double[] a = new double[10000]

unmanagedFunction(a);

that is suppose to work? What is the type to be
specified as the parameter ?

unmanagedFunction(double[] a);

That will perform pinning, pass the array by reference
and not make extra copies?

Thanks!
Atmapuri
Sep 7 '06 #5
>What is the type to be specified as the parameter ?
>
unmanagedFunction(double[] a);
Correct

>That will perform pinning, pass the array by reference
and not make extra copies?
Yes. See

http://msdn2.microsoft.com/en-us/library/23acw07k.aspx
http://msdn2.microsoft.com/en-us/library/75dwhxf7.aspx

"As an optimization, arrays of blittable types and classes containing
only blittable members are pinned instead of copied during
marshaling."

You only have to pin it manually if the native function stores the
array pointer, so it has to be valid even after the function returns.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 8 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

57 posts views Thread by Chris Foote | last post: by
16 posts views Thread by Dukkov | last post: by
21 posts views Thread by ico.bukvic | last post: by
7 posts views Thread by =?Utf-8?B?U3RldmVa?= | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.