Description
@LarsAsplund and @umarcor, here is the discussion I promised on Gitter.
In their current form, I find the storage data structures for string_ptr
and integer_vector_ptr
a bit confusing. I think I can simplify them.
So far, you have kept the original definition of string_ptr_t
, containing only the ref
element. The value ptr.ref
indexes into st.idxs
which retrieves a storage_t
element containing the mode
and another reference id
. The value of id
then indexes either st.ptrs
or st.eptrs
, depending on mode
. The types and shared variables in question are given below.
type string_ptr_t is record
ref : index_t;
end record;
type storage_t is record
id : integer;
mode : storage_mode_t;
length : integer;
end record;
type storage_vector_t is array (natural range <>) of storage_t;
type storage_vector_access_t is access storage_vector_t;
type ptr_storage is record
idx : natural;
ptr : natural;
eptr : natural;
idxs : storage_vector_access_t;
ptrs : vava_t;
eptrs : evava_t;
end record;
shared variable st : ptr_storage := (0, 0, 0, null, null, null);
I see a few different problems with this. First, you have to index into an array twice for every access of a string_ptr
. That's a bit awkward. Second, you are storing a useless length
parameter for every internal string_ptr
.
I think I can improve the structure by shifting things around slightly.
The mode
should be added to string_ptr_t
, because it represents an intrinsic attribute of a string_ptr
. The mode
of a string_ptr
will never change after its creation, so this isn't a problem when treating string_ptr
values as constants.
Storing a length
attribute is only necessary for external pointers. Because of this, the storage requirements for internal and external string_ptr
s are fundamentally different. Therefore, they should use distinct storage systems.
Below, I propose a new set of definitions to resolve these problems.
type string_ptr_t is record
ref : index_t;
mode : storage_mode_t;
end record;
type ext_storage_item_t is record
acc : extstring_access_t;
length : integer;
end record;
type ext_storage_vector_t is array (natural range <>) of ext_storage_item_t;
type ext_storage_vector_access_t is access ext_storage_vector_t;
shared variable int_storage : vava_t := null;
shared variable int_index : natural := 0;
shared variable ext_storage : ext_storage_vector_access_t := null;
shared variable ext_index : natural := 0;
Now, you only need to perform one indexing operation when accessing a string_ptr
, because the mode
attribute is able to break the ambiguity immediately.
If you agree with this new structure, I will make these changes while I make the other modifications necessary for my new queue implementation.