Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Element 0 in arrays
#5
(09-18-2023, 06:35 AM)PhilOfPerth Wrote: This may become significant for memory usage with multi-dimensional arrays:
Dim var(10, 1000) would occupy space for about 11 * 1001 units (11011), not 10000 as I would expect.

To be honest, I'd say this is negligible for todays memory setups:

eg. DIM var(1000, 1000, 1000) AS DOUBLE

You'd expect 1'000'000'000 elements, but for real its 1'003'003'001 elements, hence you've 3'003'001 elements more each 8 bytes (DOUBLE), so its approx. 24MB more.
For SINGLE or LONG (4 bytes each) arrays it would only be 12MB and for INTEGER (2 bytes) it would be 6MB more space.

Even on my old Laptop with ONLY 4GB RAM I wouldn't care about the additional 6-24MB, but for real I trained myself already years ago to DIM one index less than I need and always start my counting at index zero Big Grin , that habit it's much easier because other languages like C/C++ don't have the ability of an OPTION BASE 1, but always start at element zero.
Reply


Messages In This Thread
Element 0 in arrays - by PhilOfPerth - 09-18-2023, 06:35 AM
RE: Element 0 in arrays - by RhoSigma - 09-18-2023, 07:14 AM
RE: Element 0 in arrays - by PhilOfPerth - 09-18-2023, 11:17 AM
RE: Element 0 in arrays - by SMcNeill - 09-18-2023, 07:40 AM
RE: Element 0 in arrays - by RhoSigma - 09-18-2023, 12:58 PM
RE: Element 0 in arrays - by a740g - 09-18-2023, 01:40 PM
RE: Element 0 in arrays - by RhoSigma - 09-18-2023, 02:05 PM
RE: Element 0 in arrays - by mnrvovrfc - 09-18-2023, 02:31 PM
RE: Element 0 in arrays - by PhilOfPerth - 09-19-2023, 06:36 AM



Users browsing this thread: 4 Guest(s)