Results 1 to 10 of 10

Thread: Help large multidimensional arrays

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    currently you have 3 dimensions each of 65536 elements which I'm guessing you don't want.

    The structure you have at the moment would be one used for volumetric data, like the data you get brain MRI scan, 65536 images, all of them 65536 by 65536 pixels. An absolutely *huge* amount of data!

    Some algorithms for AI that you might of worked on store an image and the 'organisms' are only pixels in that image and data about them isn't stored anywhere else (such as the classic 'game of life')


    However you will have far, far faaaar less organisms than you will have pixels, so it's more efficient to store data per organism :

    Code:
    type
      TOrganism = record
        PositionX : integer;
        PositionY : integer;
        PositionZ : integer;
        ColourR : byte;
        ColourG : byte;
        ColourB : byte;
      end;
    Now lets say you have 1000 organisms in your world :

    Code:
    var
      Organisms : array[0..999] of TOrganism;

    you can access them like this :

    Code:
    Oganisms[22].PositionX := 10;

    Now to render the organisms, rather than iterate (loop) over every pixel in your array and draw its colour, you iterate over your organisms and draw them at their stored position.

    A rough example in 2d :

    Code:
    For I := 0 to high(organisms) do
    begin
      Image.Pixels[organisms[I].PositionX, organisms[I].PositionY].Red := organisms[I].ColourR;
      Image.Pixels[organisms[I].PositionX, organisms[I].PositionY].Green := organisms[I].ColourG;
      Image.Pixels[organisms[I].PositionX, organisms[I].PositionY].Blue := organisms[I].ColourB;
    end;
    Per pixel access will probably be more like : Image.Pixels[2,2] := RGB(RedValue,GreenValue,BlueValue) rather than a seperate byte for each colour but you get the idea.

    Basically flip your logic on it's head, rather than storing all the data on every pixel which as a whole contain all your organisms, just store the data on your organisms and save yourself a ton of memory and speed (it's a lot quicker to draw 1000 pixels than it is 65536x65536 pixels)

    You will probably have more questions so please feel free to ask


    (long story short, you can use arrays like you're trying to use them but you're using such a huge, huge, huuuge number of entries that it's just going to crash and fall over. Whatever it is that you're trying to do, I can promise you that there are far easier ways to do it, just give us more info)
    Last edited by SilverWarior; 18-01-2015 at 07:35 PM. Reason: Wraping code into code fields
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •