.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

A question on C# classes for Acad

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
211 Views, 4 Replies

A question on C# classes for Acad

In an app I'm working on I have several (non static) classed defined.
A couple of these, lets call them CLASS-A and CLASS-B deal with
particular types of blocks.
During the course of my apps life, its likely these classes will be
instantiated more than once. What can happen then is I may have several
objects of CLASS-A which may be associated with the same block
reference. This is not the type of behavior I want. With C++ this wasn't
an issue because I'd delete the object after using it, not so with C#.
So how could I go about creating an object only if it does not already
exist or is not associated with a block ref that is already being "watched"?
I would not think that making these classes "disposable" would help.
Calling dispose is not like deleting in C++, the object will still be in
memory and still accessible.
Make the class Static and just have its methods reference a different
block each time its called, depending on circumstances?
Thanks for any tips.
Perry
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Another option:
Make the class abstract (like the docdata class in the jig example)
and implement in it a hashtable and have this abstract version
instantiate a concrete version only if there is not one in the hashtable.?
Message 3 of 5
Anonymous
in reply to: Anonymous

.NET IDisposable interface does a portion of C++'s "delete", namely the
deallocation of resources (of course in .NET, the GC handles the actual
free() to release memory). Once an object has been Dispose()'d, it really
shouldn't be used anymore; you can make your methods throw an
ObjectDisposedException.

Dan

"perry" wrote in message
news:5380800@discussion.autodesk.com...
In an app I'm working on I have several (non static) classed defined.
A couple of these, lets call them CLASS-A and CLASS-B deal with
particular types of blocks.
During the course of my apps life, its likely these classes will be
instantiated more than once. What can happen then is I may have several
objects of CLASS-A which may be associated with the same block
reference. This is not the type of behavior I want. With C++ this wasn't
an issue because I'd delete the object after using it, not so with C#.
So how could I go about creating an object only if it does not already
exist or is not associated with a block ref that is already being "watched"?
I would not think that making these classes "disposable" would help.
Calling dispose is not like deleting in C++, the object will still be in
memory and still accessible.
Make the class Static and just have its methods reference a different
block each time its called, depending on circumstances?
Thanks for any tips.
Perry
Message 4 of 5
Anonymous
in reply to: Anonymous

J. Daniel Smith wrote:
> .NET IDisposable interface does a portion of C++'s "delete", namely the
> deallocation of resources (of course in .NET, the GC handles the actual
> free() to release memory). Once an object has been Dispose()'d, it really
> shouldn't be used anymore; you can make your methods throw an
> ObjectDisposedException.
>
> Dan
>
Yes, I have read that.
Still looking for input on the original question.
I tried making the classes in question static, which
of course means I don't have any redundant objects but
that raises other issues to deal with.
Perhaps the abstract class idea is the best but I'm still
trying to understand just how the "docdata" classes
(in the palette sample) work.
Perry
Message 5 of 5
Anonymous
in reply to: Anonymous

I guess this has never been an issue for anyone eh?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost