Large object heap...

A

Atmapuri

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
 
M

Michael Nemtsev

Hello Atmapuri,

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

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

A> Is the limit of 1000 elements as the switching point
A> between small and large object heap
A> fixed 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
 
M

Mattias Sjögren

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
 
W

Willy Denoyette [MVP]

| 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.
 
A

Atmapuri

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
 
M

Mattias Sjögren

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top