473,795 Members | 2,840 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with std::stable_sor t on a std::vector<gcr oot<T> >

Has anyone ever tried to sort a Standard Library container of gcroots? I
have run into the problem that somewhere deep in the Library logic (in
line 338 of <memory>, to be precise) the destructor of a class
_Temp_iterator tries to obtain the address of a gcroot, but fails
because gcroot::operato r& is private.

--
Gerhard Menzl

#dogma int main ()

Humans may reply by replacing the obviously faked part of my e-mail
address with "kapsch".
Nov 17 '05 #1
5 2639

"Gerhard Menzl" <ge***********@ spambucket.net> skrev i meddelandet
news:41******** @news.kapsch.co .at...
Has anyone ever tried to sort a Standard Library container of gcroots?
I have run into the problem that somewhere deep in the Library logic
(in line 338 of <memory>, to be precise) the destructor of a class
_Temp_iterator tries to obtain the address of a gcroot, but fails
because gcroot::operato r& is private.


An object stored in a standard container must be CopyConstructib le,
which includes having a public operator& returning the address of the
object.
Bo Persson
Nov 17 '05 #2
> Has anyone ever tried to sort a Standard Library container of gcroots? I
have run into the problem that somewhere deep in the Library logic (in
line 338 of <memory>, to be precise) the destructor of a class
_Temp_iterator tries to obtain the address of a gcroot, but fails
because gcroot::operato r& is private.


Although you can easely avoid this restriction I should point out that
gcroot isn't as light as pointers. Its copy involves "GCHandle::Allo c" -
registration of managed pointer handler. The better way is to have gcroot in
some object which is not moved around.
--
Vladimir Nesterovsky
e-mail: vl******@nester ovsky-bros.com
home: http://www.nesterovsky-bros.com
Nov 17 '05 #3
Vladimir Nesterovsky wrote:
Although you can easely avoid this restriction I should point out that
gcroot isn't as light as pointers. Its copy involves "GCHandle::Allo c" -
registration of managed pointer handler. The better way is to have gcroot in
some object which is not moved around.


I am well aware that there is a lot more going on behind the scenes when
copying GCHandles than with pointers, and I don't have a performance
problem with it. What I do have a problem with is having to add yet
another wrapper whenever I want a Standard Library container of managed
types. I also don't see how I could prevent such a wrapper object from
being moved around: as soon as it is put into a standard container, it
(and the GCHandle it wraps) *will* be copied. The only way to prevent
this would be to not using standard containers of managed objects in the
first place.

Interestingly, std::sort does not exhibit the described problem.

--
Gerhard Menzl

#dogma int main ()

Humans may reply by replacing the obviously faked part of my e-mail
address with "kapsch".
Nov 17 '05 #4
Bo Persson wrote:
An object stored in a standard container must be CopyConstructib le,
which includes having a public operator& returning the address of the
object.


Thanks for pointing this out. This seems like a major design flaw of
gcroot to me. After all, gcroot is described as a way of storing managed
objects in Standard Library containers. See
http://www.codeproject.com/managedcp...asp?print=true, for example.

--
Gerhard Menzl

#dogma int main ()

Humans may reply by replacing the obviously faked part of my e-mail
address with "kapsch".
Nov 17 '05 #5

"Gerhard Menzl" <ge***********@ spambucket.net> skrev i meddelandet
news:41******** @news.kapsch.co .at...
Bo Persson wrote:
An object stored in a standard container must be CopyConstructib le,
which includes having a public operator& returning the address of the
object.


Thanks for pointing this out. This seems like a major design flaw of
gcroot to me. After all, gcroot is described as a way of storing
managed objects in Standard Library containers. See
http://www.codeproject.com/managedcp...asp?print=true, for
example.


That's interesting. It's sort of a solution that almost works. :-)

Guess that is the best you can do under the circumstances.
Bo Persson
Nov 17 '05 #6

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

Similar topics

0
1343
by: Gerhard Menzl | last post by:
The following Managed C++ code when built using Visual Studio .NET 2003: #include <vector> #include <vcclr.h> __gc class Tester { public: typedef gcroot<Object*> TestPtr;
0
10448
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...
0
10217
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9046
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
7544
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
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
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
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
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.