Jump to content

David Heffernan

Members
  • Content Count

    3710
  • Joined

  • Last visited

  • Days Won

    185

Posts posted by David Heffernan


  1. 23 minutes ago, PeterPanettone said:

    Is that a MORAL or RELIGIOUS assessment?

    No. It's a suggestion that if you want an improvement to an open source project then one option is that you contribute it yourself. 

     

    ALL-CAPSing the project maintainer is a strategy that in my opinion is sub optimal for your goals. 

    • Like 2

  2. 11 minutes ago, Fr0sT.Brutal said:

    I once thought on a structure consisting of multiple blocks (arrays) but uniting them with common index. But I never really needed it 😄

    Implementation would be quite trivial though.

     

    {$POINTERMATH ON}
    function TBlockAllocatedList<T>.GetItem(Index: Integer): P;
    var
      BlockIndex, ItemIndex: Cardinal;
    begin
      Assert(InRange(Index, 0, Count-1));
      DivMod(Index, FItemsPerBlock, BlockIndex, ItemIndex);
      Result := P(FBlocks[BlockIndex]) + ItemIndex;
    end;
    {$POINTERMATH OFF}

     

    That's the key function in my implementation.


  3. 9 minutes ago, dummzeuch said:

    There are other structures that don't actually need contiguous areas of memory, e.g. linked lists or some tree structures. But of course these have other weaknesses.

    I'm talking about an array like structure (i.e. O(1) random access, contiguous indices) whose backing allocation is not contiguous.

     

    I'm not aware of many (if any) collections in widespread use that are like this.  I introduced such classes in my codebase in the bad old 32 bit days when address space fragmentation was killing me.


  4. No it doesn't. It's just a wrapper for an array. Effectively it's the exact same data type but with a lot of helper methods to let you write higher level code. And an allocation strategy that overallocates to avoid performing heap allocation every time you add an item.

     

    I'm not sure that there are many collection libraries that implement array like collections as anything other than a contiguous array. I know my own personal code has some classes that do this, to avoid address space fragmentation. Less of a problem now that we have 64  bit. 

    • Like 1

  5. 24 minutes ago, Mike Torrettinni said:

    Thanks! By setting Capacity (vDataList.Capacity := vMax;) I can make it work as efficient as TArray. I was under impression TList has this magical power of handling with memory, I guess it still needs a little help here and there.

     

     

    How could it possibly know how many items were going to be added?

     

    In reality you often don't know this. I would not be surprised if your array code has lots of lines like SetLength(arr, Length(arr) + 1) which are hideously inefficient.

×