Pretty simple question here, I'm a little unsure of the memory allocation in C.
If I have the following
CGPoint* tileForCoordinates (CGPoint position, short width, short height) { CGPoint *tileCoordinate = (CGPoint*)malloc(sizeof(CGPoint)); tileCoordinate->xTile = (position.xPosition / width); tileCoordinate->yTile = (position.yPosition / height); return tileCoordinate; }
and I wanted to name it in another source file or something else, would I declare a pointer and higher and return it? If so, when I call from another class, for example.
CGPoint *currentTilePosition = tileForCoordinates(curPosition, 50, 50);
What happens to the pointer returned by malloc? Should he be released or what story? :)
source share