Storing and retrieving numbers

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Storing and retrieving numbers

Post by bjb007 » Wed Sep 17, 2008 2:34 am

I've used three different ways to
store a comma-delimited string
of numbers.

1. In a field
2. In a variable
3. In an array

Assuming that the field doesn't need to
be visible is any one of these options
preferable as far as the Rev engine is
concerned for better performance?
Life is just a bowl of cherries.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Wed Sep 17, 2008 12:26 pm

As everything happens in memory, there should be no difference as long as the field is invisible - though the engine may still try and do some work to determine if things need to be wrapped even though no redraw is needed.
If the data must be saved with the stack, fields are the obvious solution, but if it's just 'in memory' storage, go for variables. When you're using arrays, you may have a tiny overhead because of the way the array element is retrieved (arrays are actually 'hash maps' aka 'dictionaries') but this is negligible.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Sep 17, 2008 2:17 pm

Hi bjb,

You can't simply ask which one is faster. Just to give you a few examples, it looks like the repeat for each command is faster with fields; using an array may be faster than using an offset if you're using fields; if the content of the field is continuously changing a simple variable might be faster; if you use repeat with x = a to b, you might want to use fields; if you only need a look-up table outside a repeat loop then arrays may be fastest. The only correct answer probably is that you've got to try.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply