>> If i have a set of overloaded serialization routines such as
>> void Serialize(ref Int32 x);
[quoted text clipped - 27 lines]
> method to call it so that the compiler knows at the time it generates the
> call what the type is.
thanks yeah I guesed it was something like that, it makes sense,
but it need a lot of different functions wich is why id rather use generic,
id rather the compiler generate loads of different functions at compile time
than have to do it by hand.
Ive tried passing it a delegate wich would probably be quicker than doing a
test in the routine for each element.
if i have my serializer :-
public abstract class SerializeStream
{
public delegate void serlizer<T>(ref T data);
public abstract void SerializeArray<T>(ref T[] array, serlizer<T>
serialize);
....
}
and call
file.SerializeArray(ref NameTable,file.Serialize);
luckily it picks up the non generic function and passes it to the array
serializer,
presumably its becuse it does it before it goes all generic.
I still need to cope with the case where the array element type class has
its own serialization routine,
I expect I can use a delegate here too but the syntax is doing my head in
trying to get it right,
although its expecting a function to be a meber of the serialize class, not
a diferent class :s
I cant use a static method becuase it needs to be overriden.
theres probably 100mb of data to be serialised this way, using reflection
everywhere is quite slow,
although neccessary for some user added classes.
Colin =^.^=
Ben Voigt [C++ MVP] - 24 Mar 2008 15:11 GMT
>>> If i have a set of overloaded serialization routines such as
>>> void Serialize(ref Int32 x);
[quoted text clipped - 63 lines]
> reflection everywhere is quite slow,
> although neccessary for some user added classes.
Use reflection to grab the serializer method and create a delegate, use a
dictionary to cache the result so you only need to do that once per type.
> Colin =^.^=
colin - 25 Mar 2008 03:39 GMT
> Use reflection to grab the serializer method and create a delegate, use a
> dictionary to cache the result so you only need to do that once per type.
yeah thats quite a good aproach, actually ive used it to handle the
reflection on some of the more complicated stuff,
as it was quite slow but with the simpler functions I was hoping to have
next to no look up,
fortunatly passing a delegate from outside the generic function it picks up
the non generif function ok.
It taxes me a bit trying to work out the way to use delegates where the
function is a ref parameter of different types,
as I cant make the parameter an object and stil be able to pass it as a
reference.
ive tended to avoid trying to do it this way for the stuff that will get
used heavily.
Colin =^.^=