Do you want a fast solution or a nice solution? I would create a string
$str = ''; and do
vec($str, 999999, 8) = 0; This is probably the fastest way to initialize a table (not to mention it's also the most memory-efficient solution as well.) This will initialize an "array" of characters 1000 x 1000. To access any value in this array, simply do this:
vec($str, $Y*1000+$X, 8) where $X and $Y are the coordinates of your char array. If you need an array of integers, simply change the number 8 to 16 (or 32 for an array of 32-bit integers.)
EDIT: To make it slightly more efficient, the "width" of your array should be a power of 2. So, instead of 1000 x 1000, you'd create 1024 x 1000, and then you would access any value in the array by doing this instead: vec($str, $Y << 10 | $X, 8) The only difference is that now we use the bitwise << shift operator and | OR operator in the calculation instead of multiplication and addition. When you use multiplication, Perl assumes that you're multiplying a 64-bit double, so it executes the FMUL function which is slow. But when you do bitwise operations, your calculation is classified as integer math which is way faster, especially when you have to do millions of calculations.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.