473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

life-time pinning. vs Global heap


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.
Jan 3 '08 #1
4 2108
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.
Jan 3 '08 #2
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.
Jan 3 '08 #3
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.

Jan 3 '08 #4
Reasoning: (for better or worst)
The byte array is used throughout the life time of the program,
and would have to be fixed -least- every 20ms for processing.
The Idea is that the array would be up and out of the way from
the garbage collector, because there realy isnt a point in including
it in the gc process.

I know the fixed statement doesnt incurr much at all for pinnning,
atleast until the garbage collection cycle is triggered when the
object is pinned.

"Nicholas Paldino [.NET/C# MVP]" wrote:
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.


Jan 3 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: cognite | last post by:
This venue would surely appreciate the cool stuff being done in python on bioinformatics and python's tools for info parsing and extraction (like fulltext indexing, xml tools, parser builders,...
1
by: Johnny A. Stoa | last post by:
PRESS RELEASE I am pleased to forward to you our official press release related to the launch of our new software product Life*TYPE. Life*TYPE is an XML/SGML formatting and paginating COTS...
6
by: Paul | last post by:
In real life situation, do we ever come across a situation where we would need two base objects in an object. A snippet is worth 1000 words (: so... class Base { }; class Derived1:public Base...
3
by: bb | last post by:
Hi, Have a query regarding the life of temporaries. Here is the code... class MyNumber { public: MyNumber(int n) : n(n) { cout << "Object Constructed." << endl; }
6
by: CapMaster | last post by:
I'm having some trouble programming the game of life. In the version my teacher gave us, it involves a class with a private grid variable for the game. Here's the class she gave us: .. const int...
1
by: blackslither | last post by:
I had to implement Game of Life in a 3D matrix (int a) , but the complexity of my implementation is O(n^6) (6 imbricated for) and it runs very slow . Can anyone help me with an optimized version of...
0
by: Let U Know All | last post by:
Life happy life http://143life.blogspot.com/
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.