C-Struct vs Object

I am currently working on Conway's Game of Life simulator for iPhone, and I had a few questions about memory management. Please note that I am using ARC.
For my application, I will need a large number of C style structsor Objective-C objects to represent cells. There may be several thousand of them, so it is obvious that memory management came to mind. My argument for structures is that the cells do not require typical OO properties. The only thing they will hold is two meanings
structsBOOL, therefore, there will not be a huge amount of memory chewed by these cells. In addition, I need to use a two-dimensional array. With structs, I can use 2-dimensional C-style arrays. To my knowledge, there is no substitute for this in Objective-C. I feel that it is too difficult to create an object for only two Boolean values.
Objective-C objects My argument (and most other people) is that managing memory around Objective-C objects is very simple and efficient with ARC. In addition, I saw the arguments that a is structnot such a large memory reduction for an object.

So my question. Should I go with the old school, skinny and compatible with a two-dimensional array structs? Or should I stick with typical Objective-C objects and risk using extra memory.

Follow-up thoughts: If you recommend Objective-C objects, provide an alternative storage method, which is a two-dimensional array. This is critical and is one of the biggest drawbacks of transitioning with Objective-C objects.
Thankyou.

+4
source share
3 answers

" - "... Game of Life, 100 000 , . , , . , , , () . . , ... , , , ? ( , ...) , , . $.02...

+4

2 BOOL, , . :

, bool: boolX boolY, int :

int combinedBool = boolY + (10*boolX);

, bool, :

BOOL boolX, boolY;
boolX = combinedBool/10;
boolY = combinedBool%10;

, ((yIndex*width)+xIndex), width - , xIndex yIndex X Y .

, .

+2

You can build one and check its size with malloc_size(myObject). Thousands of pairs of bolts will be small enough. In fact, you can make objects larger and take advantage of OO design. For example, what if cells also contained pointers to neighboring cells. Cells could calculate their own t + 1 state with cached access to their neighbors.

0
source

Source: https://habr.com/ru/post/1534750/


All Articles