|
Posted by Toby A Inkster on 04/30/07 10:49
brainflakes.org wrote:
> Are there actually any proper binary extensions or is using gd lib the
> way to go (as I guess it's just dealing with binary data as a 2d array
> anyway)
Assuming that each "row" of data is of the same length, and each "column"
has the same height (which I think is a fairly safe assumption if you're
modelling the data as a rectangular image) then, why not just store the
data as a string. That is, instead of storing a 3x3 array of data as this:
$array = array(
array(0x61, 0x62, 0x63),
array(0x31, 0x32, 0x33),
array(0x78, 0x79, 0x7A)
);
you store it as:
$string = 'abc123xyz';
Which is roughly how a 2-dimensional array is internally stored by a C
program.
Instead of this:
$cell = $array[$x][$y];
You use:
define(ROW_LENGTH, 3);
$cell = $string[(ROW_LENGTH*$x) + $y];
And instead of this:
$array[$x][$y] = 0x64;
this:
$string[(ROW_LENGTH*$x) + $y] = chr(0x64);
--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
Navigation:
[Reply to this message]
|