x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

[C++] How do i initialize the size of a 3D Array in c++ in a method

Hi. I want to store my block actor data in a 3D array. So i can just call blocks[x][y][z] and get the block at the give coordinate. Atleast this worked in java but not in c++. Is there a way to store my 3D block data in a 3D Array where i can set the size of it in a method ?

Product Version: UE 4.11
Tags:
more ▼

asked May 22 '16 at 06:17 PM in C++ Programming

avatar image

Gunschlinger
116 16 23 41

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Ok so you declare a 3d array first and specifying the size in subscript operator so to stor a pointers you wold do it like this

 MyDataType* mydata3dArray[sizeX][sizeY][sizeZ];
 
 //and use it this way
 
 mydata3dArray[indexX][imdexY][indeZ] = Data;

Note that the size must be known at compile time and must be a constant value

more ▼

answered May 22 '16 at 07:14 PM

avatar image

Mlody "Swidwin"
327 12 12 25

avatar image Gunschlinger May 22 '16 at 07:17 PM

So i cant have something like this ? Like dynamicly change the size of the array ? Like when i am loading a new level in?

 int[][][] array;
 
 public void main()
 {
      int x = 5;
      array = new int[x][x][x];
 }

avatar image Mlody "Swidwin" May 22 '16 at 07:22 PM

No arrays in c++ are different from c# you will have to declare array as a pointer to pointer to poiner and allocate memory your self for dynamic arrays

http://stackoverflow.com/questions/10238699/dynamically-allocating-3d-array

avatar image Gunschlinger May 22 '16 at 07:35 PM

thats sad. But the link you send me should do the trick. Thanks for your help

avatar image Mlody "Swidwin" May 22 '16 at 07:49 PM

No is not do your lessons ! Memory management is very important. c++ is unmanaged you have to code stuff yourself if you want array like this than you can use a class templates to develop a type witch will behave jus as you want. it ain't that hard I though is something hard to do but guess what I've ended up developing entire memory management system for my portfolio project including dynamic allocation size pool, fixed allocation size pool, memory manager with leak tracking system and entire allocation inteface for win32 platform, actually I've deveooped entire game framework including game AI system and procedurall generation algorithm you can check part of my progress here https://www.youtube.com/channel/UCfQtxQv9UJLyYkRziUE7yFQ/videos?sort=dd&view=0&shelf_id=0

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Yes there is but the question is how you are going to manage memory ? Do you want an dynamic array allocated on heap or your array size will be fixed for the entire run time and allocated on stack ? Another thing is if you want to store the actual data in array or just ponters to data or even the references ?

more ▼

answered May 22 '16 at 07:02 PM

avatar image

Mlody "Swidwin"
327 12 12 25

avatar image Gunschlinger May 22 '16 at 07:04 PM

i want to store Pointer refs to blocks at the given x,y,z location. The Array will have a fixed size because of the level size.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question