I'm working on a ray tracer and I wanted to use ObjC with garbage collection because of its ease of use and flexibility.
I thought about using structures for this libraries primitives, but I think I'm better off using ObjC classes and if the function is time consuming - just use c functions to access the ivar directly instead of using a property. So really in some cases I might just be using Objc class as a simple container to go into an NSArray.
For example:
Both the method and function below will do the same thing, but the call time on the global function is shorter. When the vertex goes out of scope the garbage collector deals with it.
The other idea was just to use structs tagged as __strong when they were children of other structs.
I thought about using structures for this libraries primitives, but I think I'm better off using ObjC classes and if the function is time consuming - just use c functions to access the ivar directly instead of using a property. So really in some cases I might just be using Objc class as a simple container to go into an NSArray.
For example:
Code:
@interface Vertex {
@public
float x,y,z;
}
@property (assign) x;
@property (assign) y;
@property (assign) z;
- (void)zero;
@end
@implementation
@synthesize x,y,z;
- (void)zero {
x = 0;
y = 0;
z = 0;
}
@end
void zeroVertex(Vertex* v) {
v->x = 0;
v->y = 0;
v->z = 0;
}
Both the method and function below will do the same thing, but the call time on the global function is shorter. When the vertex goes out of scope the garbage collector deals with it.
Code:
Vertex* vertex = [Vertex new];
[vertex zero];
zeroVertex(vertex);
vertex = nil;
The other idea was just to use structs tagged as __strong when they were children of other structs.