Home All Groups Group Topic Archive Search About

C# CSharp Reset Struct Class Memory

Author
21 Mar 2007 5:25 PM
Sheikko
C# CSharp Reset Struct Class Memory

Hi,
I have a class, cerated like a struc for some reasons, and I want to
reset all values in it.

    public class MyClass
    {
        public byte Channel;
        public byte SatelliteID;
        public byte SyncFlags;
        public byte PhaseErrorCount;
    }

After filling the class with some values, I want to reset all values
to the default, like the first time it was created.
I can do this filling every parameter, but I have some classes with a
lot of parameteres.
there is a way to reset this class? For example clear the memory
occupied by the class.
I know that I can make assigning a NULL to the class and recreate it,
but I search another way.

THank you very much

Author
21 Mar 2007 5:59 PM
Cowboy (Gregory A. Beamer)
Unless you create a reset method and reset things, there is no automagic way
to do it.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*********************************************
Think outside the box!
*********************************************
Show quote
"Sheikko" <shei***@gmail.com> wrote in message
news:1174497908.565321.309670@p15g2000hsd.googlegroups.com...
> C# CSharp Reset Struct Class Memory
>
> Hi,
> I have a class, cerated like a struc for some reasons, and I want to
> reset all values in it.
>
>    public class MyClass
>    {
>        public byte Channel;
>        public byte SatelliteID;
>        public byte SyncFlags;
>        public byte PhaseErrorCount;
>    }
>
> After filling the class with some values, I want to reset all values
> to the default, like the first time it was created.
> I can do this filling every parameter, but I have some classes with a
> lot of parameteres.
> there is a way to reset this class? For example clear the memory
> occupied by the class.
> I know that I can make assigning a NULL to the class and recreate it,
> but I search another way.
>
> THank you very much
>
Author
29 Mar 2007 5:36 PM
Kiran Prabhu
you can add structlayout [sequential ] attribute on the class and then copy
a byte array of  the class size over the class each time you need to reset.
you can use "marshal.copy" to copy the byte array
this will work fine if you are using only value types in the class otherwise
you need to do some extra work if it contains references

kiran prabhu

Show quote
"Sheikko" <shei***@gmail.com> wrote in message
news:1174497908.565321.309670@p15g2000hsd.googlegroups.com...
> C# CSharp Reset Struct Class Memory
>
> Hi,
> I have a class, cerated like a struc for some reasons, and I want to
> reset all values in it.
>
>     public class MyClass
>     {
>         public byte Channel;
>         public byte SatelliteID;
>         public byte SyncFlags;
>         public byte PhaseErrorCount;
>     }
>
> After filling the class with some values, I want to reset all values
> to the default, like the first time it was created.
> I can do this filling every parameter, but I have some classes with a
> lot of parameteres.
> there is a way to reset this class? For example clear the memory
> occupied by the class.
>  I know that I can make assigning a NULL to the class and recreate it,
> but I search another way.
>
> THank you very much
>

AddThis Social Bookmark Button