473,664 Members | 2,728 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2125
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
"TheMadHatt er" 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
"TheMadHatt er" 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.co m

"TheMadHatt er" <Th**********@d iscussions.micr osoft.comwrote in message
news:E5******** *************** ***********@mic rosoft.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
"TheMadHatte r" 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.co m

"TheMadHatt er" <Th**********@d iscussions.micr osoft.comwrote in message
news:E5******** *************** ***********@mic rosoft.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
"TheMadHatt er" 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
1714
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, graphic display, realtime simulation and communities tools like pygame and ...) It's in San Diego February 9-12, 2004. "Session presentations are 45 or 90 minutes long, and tutorials are either a half-day (3 hours) or a full day (6 hours)."
1
1560
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 engine. The engine has been part of our XML/SGML content repository, Life*CDM, for years but is now also available as a stand-alone product. The press release can be read at
6
2827
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
1646
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
4779
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 maxrow = 20, maxcol = 60; // grid dimensions class Life { public: Life (); void initialize(); void print(); void update(); private:
1
2176
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 Game of life , even with a 2D matrix . Or how the Game of Life in general could be optimized ?
0
938
by: Let U Know All | last post by:
Life happy life http://143life.blogspot.com/
0
8861
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7375
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4185
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2764
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1759
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.