Archived

This forum has been archived. Please start a new discussion on GitHub.

problem about Union

I have constructed a data access utility with IDL provided by http://www.omg.org/technology/documents/formal/UMS_Data_Access_Facility.htm with ACE/TAO. It seems that the efficiency is very high.
Now I'm considering to construct it with Ice, but i have a doubt:

For Data Access Utility, union will be used a great deal for several basic data types, such as float,int,string. But Slice realize union as class, i guess it may affect the efficiency a lot.

I think union in this situation is necessary. If there's no union, for 2-dimension data( such as the map of database table ) will be stored as pointer, for the reason vector can only store isomorphic elements. This will make lots of call new and construction and destruction.

Any idea ?

Comments

  • Re: problem about Union
    Originally posted by minifat
    I have constructed a data access utility with IDL provided by http://www.omg.org/technology/documents/formal/UMS_Data_Access_Facility.htm with ACE/TAO. It seems that the efficiency is very high.
    Now I'm considering to construct it with Ice, but i have a doubt:

    For Data Access Utility, union will be used a great deal for several basic data types, such as float,int,string. But Slice realize union as class, i guess it may affect the efficiency a lot.

    Any idea ?

    I'd suggest you try this. Chances are that the impact on efficiency will be zero. You can simulate a union using a base class and derived classes. You can put a discriminator into the base class, for example:
    enum UnionDiscriminator { DInt, DString, DDouble };
    
    class UnionBase { 
        UnionDiscriminator d;
    };
    
    class UnionInt extends UnionBase {
        int i;
    };
    
    class UnionString extends UnionBase {
        string s;
    };
    
    class UnionString extends UnionBase {
        double d;
    };
    

    Make UnionBase the formal parameter type and use the discriminator in the base class to find out what to downcast to.

    Cheers,

    Michi.
  • Re: Re: problem about Union
    Originally posted by michi
    I'd suggest you try this. Chances are that the impact on efficiency will be zero. You can simulate a union using a base class and derived classes. You can put a discriminator into the base class, for example:

    enum UnionDiscriminator { DInt, DString, DDouble };
    
    class UnionBase { 
        UnionDiscriminator d;
    };
    
    class UnionInt extends UnionBase {
        int i;
    };
    
    class UnionString extends UnionBase {
        string s;
    };
    
    class UnionString extends UnionBase {
        double d;
    };
    

    Make UnionBase the formal parameter type and use the discriminator in the base class to find out what to downcast to.

    Cheers,

    Michi.

    yes, I'm just ready to do like this, but i have the following doubt:

    I think union in this situation is necessary. If there's no union, for 2-dimension data( such as the map of database table ) will be stored as pointer, for the reason vector can only store isomorphic elements. This will make lots of call new and construction and destruction.

    Any idea ?
  • Re: Re: Re: problem about Union
    Originally posted by minifat
    yes, I'm just ready to do like this, but i have the following doubt:

    I think union in this situation is necessary. If there's no union, for 2-dimension data( such as the map of database table ) will be stored as pointer, for the reason vector can only store isomorphic elements. This will make lots of call new and construction and destruction.

    Any idea ?

    I'm not sure I understand your question. Basically, whether you transmit a conceptual union using derived classes as I showed, or transmit them using something like a CORBA IDL union construct makes no difference. In both cases, the contents of the union are sent over the wire, preceded by a discriminator that tells the receiving end how to unmarshal what follows the discriminator. What type of data is stored in the various union members is irrelevant.

    Can you be a bit more precise as to exactly what you want to do?

    Cheers,

    Michi.
  • Sorry for my clumsy description.
    for example, with CORBA IDL unicon, i can use like this,

    sequence<Unionbase> data_row;

    data_row.length( n )
    data_row[0].float_value( 1.1 );
    data_row[1].int_value( 2 );

    but with Ice/C++

    i have to do like this

    vector<BaseClass*> data_row;
    data_row.resize( n );
    data_row[0] = new float_type;
    data_row[0]->float_val = 1.1;
    ...

    I'm not sure if the mass call of new/detele will affect the efficiency ?
    I guess in CORBA, the whole data_row memory is reserved for once, in spite of some wast, but runs much faster.
  • marc
    marc Florida
    Yes, this wouldn't be as efficient as with IDL unions.

    So far I never came across a reason to use IDL unions. Perhaps your program can be changed on a more conceptual level to not require unions? After all, languages such as Java don't have unions either.