Results 1 to 5 of 5

Thread: Mapping Slice structs to C# structs

  1. #1
    kwaclaw is offline Registered User
    Name: Karl Waclawek
    Organization: Personal
    Project: Whiteboard application
    Join Date
    Sep 2004
    Location
    Oshawa, Canada
    Posts
    159

    Mapping Slice structs to C# structs

    Currently one cannot force the code generator to map a Slice struct to a C# struct if the Slice struct contains reference types. Why is that?

    Karl
    Karl Waclawek

  2. #2
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    The main reason is that, if a structure contains a Slice class member and that class member is mapped to C# class, there is no way to unmarshal the struct corrrectly. This is because of the way Slice classes are marshaled. (See Section 39.2 in the manual.) There is simply no way to instantiate a C# struct and then, when the value of the class instance contained by the struct arrives, patch the corresponding data member in the struct.

    Also, pragmatically, as soon as a C# struct contains a reference type, there is no point in using a struct any longer--any minor performance advantage provided by using a struct effectively disappears, so you might as well use a class.

    Cheers,

    Michi.

  3. #3
    kwaclaw is offline Registered User
    Name: Karl Waclawek
    Organization: Personal
    Project: Whiteboard application
    Join Date
    Sep 2004
    Location
    Oshawa, Canada
    Posts
    159
    Quote Originally Posted by michi View Post
    The main reason is that, if a structure contains a Slice class member and that class member is mapped to C# class, there is no way to unmarshal the struct corrrectly. This is because of the way Slice classes are marshaled. (See Section 39.2 in the manual.) There is simply no way to instantiate a C# struct and then, when the value of the class instance contained by the struct arrives, patch the corresponding data member in the struct.
    I guess that answers my question. :-)

    Quote Originally Posted by michi View Post
    Also, pragmatically, as soon as a C# struct contains a reference type, there is no point in using a struct any longer--any minor performance advantage provided by using a struct effectively disappears, so you might as well use a class.
    Let's say I need to allocate a large array of structs, which can be done using a contiguous block of memory. Now, even if the structs contain references to some (possibly pre-existing) reference types, why would that negate the performance advantage of allocating one large chunk of memory vs instantiating a large number of individual objects?

    Karl
    Karl Waclawek

  4. #4
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    Quote Originally Posted by kwaclaw View Post
    Let's say I need to allocate a large array of structs, which can be done using a contiguous block of memory. Now, even if the structs contain references to some (possibly pre-existing) reference types, why would that negate the performance advantage of allocating one large chunk of memory vs instantiating a large number of individual objects?
    It won't negate the performance advantage for allocating the array. However, if each struct contains a reference member, that performance advantage is likely to drown among all the allocations for those reference members.

    In addition, when we unmarshal such an array, we then have to copy all the structs into the array by value which, unless the structs are small and simple, is more expensive than instantiating lots of classes and assigning their references. So, there really is little point in having a struct with a reference member because, in practice, it doesn't provide any advantage over mapping to a class.

    In general, C# structs should be used for small collections of data with value semantics, such as an xy coordinate or a complex number.

    Cheers,

    Michi.

  5. #5
    kwaclaw is offline Registered User
    Name: Karl Waclawek
    Organization: Personal
    Project: Whiteboard application
    Join Date
    Sep 2004
    Location
    Oshawa, Canada
    Posts
    159
    Quote Originally Posted by michi View Post
    It won't negate the performance advantage for allocating the array. However, if each struct contains a reference member, that performance advantage is likely to drown among all the allocations for those reference members.
    Yes, I can see that.

    Thanks for the explanation,

    Karl
    Karl Waclawek

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 10
    Last Post: 05-12-2010, 10:16 AM
  2. Python: repr() of Slice structs/classes
    By cebix in forum Comments
    Replies: 2
    Last Post: 04-15-2008, 08:24 AM
  3. Latency: structs vs. classes
    By n2503v in forum Help Center
    Replies: 7
    Last Post: 10-09-2005, 12:08 AM
  4. Impact of include on on structs in modules(Python)
    By petrilli in forum Help Center
    Replies: 2
    Last Post: 03-10-2005, 11:18 PM
  5. Parameterized constructors for structs?
    By shaver in forum Comments
    Replies: 3
    Last Post: 01-10-2004, 06:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •