473,385 Members | 1,919 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.

destructors not permitted for __value types.

Personally, I like to use simple abstractions to wrap resources
For example consider a class that wraps a resource - say an IntPtr which is allocated in the constructor and deallocated in the destructor.
In the managed world I find that I can not use this because destructors (and copy constructors) for value types are not allowed. Of all the restrictions when compiling managed C++ code (and there are many!) this one is one of my pet hates
To me this was quite unexpected
I do not want to allocate the class as a object on the managed heap (__gc) because that would either require explicit calling of Dispose - which defeats the purpose of the abstraction or waiting for gc - which is not what I want to do either
Are there any ways round this?
Nov 17 '05 #1
5 1251
PaulW wrote:
Personally, I like to use simple abstractions to wrap resources.
For example consider a class that wraps a resource - say an IntPtr
which is allocated in the constructor and deallocated in the
destructor.
In the managed world I find that I can not use this because
destructors (and copy constructors) for value types are not allowed.
Of all the restrictions when compiling managed C++ code (and there are
many!) this one is one of my pet hates.
To me this was quite unexpected.
I do not want to allocate the class as a object on the managed heap
(__gc) because that would either require explicit calling of Dispose -
which defeats the purpose of the abstraction or waiting for gc - which
is not what I want to do either.
Are there any ways round this?


I wish I knew how to overcome this myself, but all I can do is to assure
you that I share your sentiments. The mess called Managed C++ is a
result of foisting the design philosophy of a certain language which is
based on the illusion that garbage collection is the end of manual
resource management (Java) on a language which emphasizes deterministic
and reliable handling of resources (C++), thereby crippling it beyond
recognition.

Gerhard Menzl
--
Humans may reply by replacing the obviously faked part of my e-mail
address with "kapsch".

Nov 17 '05 #2
" deterministic and reliable handling of resources"

Thats up the the developer, no?
I would hardly call it "reliable" then.

"Gerhard Menzl" <ge***********@spambucket.net> wrote in message
news:40********@news.kapsch.co.at...
PaulW wrote:
> Personally, I like to use simple abstractions to wrap resources.
> For example consider a class that wraps a resource - say an IntPtr
> which is allocated in the constructor and deallocated in the
> destructor.
> In the managed world I find that I can not use this because
> destructors (and copy constructors) for value types are not allowed.
> Of all the restrictions when compiling managed C++ code (and there are
> many!) this one is one of my pet hates.
> To me this was quite unexpected.
> I do not want to allocate the class as a object on the managed heap
> (__gc) because that would either require explicit calling of Dispose -
> which defeats the purpose of the abstraction or waiting for gc - which
> is not what I want to do either.
> Are there any ways round this?


I wish I knew how to overcome this myself, but all I can do is to assure
you that I share your sentiments. The mess called Managed C++ is a
result of foisting the design philosophy of a certain language which is
based on the illusion that garbage collection is the end of manual
resource management (Java) on a language which emphasizes deterministic
and reliable handling of resources (C++), thereby crippling it beyond
recognition.

Gerhard Menzl
--
Humans may reply by replacing the obviously faked part of my e-mail
address with "kapsch".

Nov 17 '05 #3
PaulW wrote:
In the managed world I find that I can not use this because destructors
(and copy constructors) for value types are not allowed. Of all the
restrictions when compiling managed C++ code (and there are many!) this
one is one of my pet hates.


The main reason for not having a copy constructor and a destructor in value
classes is that the semantics would not always be adhered to. It is far
worse to allow something to work some of the time than to disallow a
behavior in total.

That said, we're addressing this issue head on in Whidbey. Value classes
will still not be allowed to have special member functions (things like
default constructors, copy constructors, destructors, and finalizers). Ref
classes will be allowed to have all of these, and ref classes will be
allowed to have stack based semantics (i.e. the language will let you put a
ref class on the stack).

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.

Nov 17 '05 #4
.. wrote:
" deterministic and reliable handling of resources"

Thats up the the developer, no?
I would hardly call it "reliable" then.


Of course it's up to the developer. It always is. What is your point?

Gerhard Menzl
--
Humans may reply by replacing the obviously faked part of my e-mail
address with "kapsch".

Nov 17 '05 #5
.. <.> wrote:
" deterministic and reliable handling of resources"

Thats up the the developer, no?
I would hardly call it "reliable" then.
The language allows you to do it in
a reliable way. That doesn't mean it
does it for you.
[...]


Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
Scott Meyers
Nov 17 '05 #6

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

Similar topics

16
by: Edward Diener | last post by:
Is there a way to override the default processing of the assignment operator for one's own __value types ? I realize I can program my own Assign method, and provide that for end-users of my class,...
3
by: Edward Diener | last post by:
In the doc regarding __value classes, under Primitive Types, I read: "Generally, the C++ types and their __value class equivalents are interchangeable in Managed Extensions." What exactly does...
8
by: Edward Diener | last post by:
I have a __value class which uses some legacy C++ code. So I wrapped the legacy C++ code in another __nogc class and have a pointer to that class as a member of my __value class. When the __value...
0
by: Edward Diener | last post by:
Why is there a prohibition of instantiating __value type enums and classes within __nogc classes ? After all __value types are not managed by the GC and built-in __value types, such as 'int', are...
15
by: Edward Diener | last post by:
Why is it impossible to have a __value class instance variable in a __nogc class when it is possible to have a built-in type instance variable in a __nogc class ? __value class X { int a; };...
0
by: Marcus Kwok | last post by:
I have been reading through the ManagedExtensionsSpec.doc file and I thought something was not clear. If I have a __value class (really a __value struct but that shouldn't make a difference) and...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.