Should size be extended to variables?

Mark Waddingham mark at livecode.com
Sat Aug 20 16:29:42 EDT 2016


This is why I asked 'for what purpose' :)

For the case of optimising for memory footprint you need a measure which allows to see the effect of your code changes on the amount of memory used whilst running - and this is entirely a runtime concern, so you need to take measurements which reflect active state.

For the case of indexing an encoded format on disk you need to measure the size of things as they are in your specific output format - that will entirely depend on how you choose to encode the values you are writing out and want to index.

The encoded size of a string, for example, will depend on the text encoding.

A good pattern for your use-case is perhaps PDF. This format is a serialised list of objects which has an index appended to the end. The index is a mapping of thing you want to load to byte offset in file. The index is generated as the file is written out (reading file offsets as they are written out), then appended to the end of the file. The final bit of the file is the byte offset to the start of the index in the file.

(Note that such an index could be generated as a post processing step, and is perfectly viable as a separate file).

In regards to 'number of bytes of', then this does an auto convert to data relative to the native encoding (for strings) so probably isn't what you want here if your text could be Unicode ( or needed in a cross platform encoding).

Warmest regards,

Mark.

Sent from my iPhone

> On 20 Aug 2016, at 20:05, Richard Gaskin <ambassador at fourthworld.com> wrote:
> 
> Mark Waddingham wrote:
> 
> 
> > On 20 Aug 2016, at 18:01, Mark Talluto wrote:
> >>
> >> On Saturday, August 20, 2016, Richard Gaskin wrote:
> >>> Any other options I should consider before submitting a request for
> >>> some means of determining data length in bytes?
> >>
> >> Yes. Arrays.
> >
> > For what purpose?
> >
> > The key thing here is that the number of bytes a value currently
> > takes up in memory is not actually a good measure for how much memory
> > is being used because instances of values can be shared.
> >
> > To put it another way, the memory footprint used by two arrays will
> > not necessarily be the same as the sum of the memory footprint of the
> > two arrays measured separately as they might share the actual memory
> > used by any value in either array. e.g the values used to store the
> > keys in an array are *always* shared.
> 
> Would that apply across sub-arrays? e.g., given:
> 
>  someKey=
>      Name=Mark
>      EmpID=2
>   anotherKey=
>      Name=Kevin
>      EmpID=1
> 
> ...would "Name" and "EmpID" use the same string in memory?
> 
> 
> As for byte sizes, my own use case is for establishing pointers to locations within a large file on disk.
> 
> But as Richmond kindly reminded me, the byte chunk type supports that with "the number of bytes of...", so I'm set for now.
> 
> 
> > For optimization purposes the best approach is to measure the amount
> > of memory *actually* in use before and after any particular operation
> > you perform - just as you do with time when profiling for speed
> > (rather than memory footprint).
> 
> Is there some built-in way to get the amount of memory in use, or are you thinking of shell calls there?
> 
> -- 
> Richard Gaskin
> Fourth World Systems
> Software Design and Development for the Desktop, Mobile, and the Web
> ____________________________________________________________________
> Ambassador at FourthWorld.com                http://www.FourthWorld.com
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list