Hmm, thanks for the reply BrowserUk. I had thought of something like this, but unfortunately I need the full array in contiguous memory at all times. The problem is that the base algorithm needs to be optimized for lookups, and as such the lookup is done in C and is a very minimal function (all precondition/postcondition checks are handled in the perl layer on STORE so the FETCH can be as minimal as possible) I will likely have to call the lookup several million times more than the store. So if I use a discontinuous representation I have to put a bunch of logic in the lookup to handle those cases, or repack the whole thing if a STORE has occured since the last FETCH, and it is precisely the last case that is the reason for me using the implementation I am. Originally I just used a normal array to represent the object from the perl POV and a packed representation (packed on demand when a FETCH occured after a STORE) for the C. However this meant that I ended up storing the data twice, and the array storage was very wasteful of ram.

Anyway, your idea made me think of an alternate strategy for allocation. The likelyhood that the base algorithm needs to extend the array is inversely proportional to the number of items in the data structure for typical data sets for what the algorithm is intended for. So I was thinking of setting up an array of allocation sizes that goes from large, say 64k down to relatively small (4096 sounds good based on the reasons you point out, thanks). This way the initial allocation will cover small data sets nicely without wasting too much ram, and later allocation will be more conservative and still end up "fitting" quite nicely. I havent done this yet, but I plan to have a look at its behaviour and see how it goes.

Cheers and thanks again for the reply. Some good stuff there.


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

In reply to Re: Re: Re: Re: Memory allocation strategies by demerphq
in thread Memory allocation strategies by demerphq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.