With all due respect, not wanting to use the fixed statement is a very,
very poor reason to keep something pinned in memory like this.
Using an unmanaged buffer is only going to help if you are not going to
access the memory outside of an unsafe context. In that case, you would
have to marshal the memory block back to managed code (and then back to
unmanaged when you are done making changes to it, as well as more than
likely protect access with a lock, if concurrency is a concern).
Why do you not want to use the fixed statement?
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"TheMadHatter" <Th**********@discussions.microsoft.comwrote in message
news:E5**********************************@microsof t.com...
Oops, sorry for the confusion....
I am using the array in an unsafe context. (via pointers.)
I do not want to continuously use the fixed(byte* ptr = myArray)
statement,
so that leaves pinning via GCHandle, or allocating on the
unmanage heap.
Thanks for the responce.
"Peter Bromberg [C# MVP]" wrote:
>The word "fix" is somewhat confusing here. If you really only need to
have
the byte array available for the lifetime of the appDomain, you can just
add
the static modifier. Or, you could create a byte array property and make
it
readonly.
--Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"TheMadHatter" wrote:
>
I am very sorry to bring a topic up that has been beaten with an ugly
stick..... but...
If I want to "fix" an byte array for the life time of a program would
it be
better allocating it on the unmanaged heap?
Yes I know that if I am to pin the object for long periods of time,
that it
would be best to do it at the very initial start of the program so that
it
prevents some fragmentation of the managed heap.
Thanks in advance for your thoughts on the matter.