Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Dynamically typecast

I am trying to write a new class that is a faster version of the dynamic array. The way I am doing it is to have a linked list with each node pointing to an array of unknown. Right now I am using variants, but I don't think it will work for records. I basically want to make it to where each node points to an array of pointers and then dynamically typecast the derefenced pointer as the type they declare it as. An example would be.

var
FastArray : TFastArray;
i : Integer;
x : Integer;
begin
FastArray := TFastArray.Create(Integer);
i := FastArray.Data[x];
end;

I need it to where Integer can be any declared type such as a record, class, string, integer... Is there any way to do this. I guess it is similar to a template class in C++.

Comments

  • MasterijnMasterijn Member Posts: 188
    : I am trying to write a new class that is a faster version of the dynamic array. The way I am doing it is to have a linked list with each node pointing to an array of unknown. Right now I am using variants, but I don't think it will work for records. I basically want to make it to where each node points to an array of pointers and then dynamically typecast the derefenced pointer as the type they declare it as. An example would be.
    :
    : var
    : FastArray : TFastArray;
    : i : Integer;
    : x : Integer;
    : begin
    : FastArray := TFastArray.Create(Integer);
    : i := FastArray.Data[x];
    : end;
    :
    : I need it to where Integer can be any declared type such as a record, class, string, integer... Is there any way to do this. I guess it is similar to a template class in C++.
    :
    Hello,
    Sorry to say, but I don't think this approach will make dynamic arrays faster. The only slow thing about dynamic arrays is, when they are resized. By allocating items in bulks and using your own count variable this performance hit can be prevented.
    Variants are useful when you don't know the type to store at forehand, but unfortunately with a performance trade-off.



Sign In or Register to comment.