en mi aplicación puedo crear un puntero char sin signo utilizando esta función:C y Objective-C - Forma correcta para liberar un puntero unsigned char
- (unsigned char*)getRawData
{
// First get the image into your data buffer
CGImageRef image = [self CGImage];
NSUInteger width = CGImageGetWidth(image);
NSUInteger height = CGImageGetHeight(image);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = malloc(height * width * 4);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextSetBlendMode(context, kCGBlendModeCopy);
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, (CGFloat)width, (CGFloat)height), image);
CGContextRelease(context);
// Now your rawData contains the image data in the RGBA8888 pixel format.
return rawData;
}
Y en otra clase asigno una propiedad para ese indicador como tal : self.bitmapData = [image getRawData];
¿Dónde en este proceso puedo liberar esa memoria malloc'd? Cuando trato de liberar la propiedad en dealloc, me da un error exc_bad_access. Siento que me falta un concepto fundamental de c o objetivo c aquí. Toda la ayuda es apreciada.
¿Cómo está liberando la propiedad? – iandotkelly
Cada asignador tiene un desasignador emparejado * para * el objeto asignado. Si mira la página de manual de ['malloc'] (http://linux.die.net/man/3/malloc), pero es la mejor para encontrar la documentación relacionada con su plataforma específica, se explicará qué se debe usar. ;-) –
Probé gratis (propiedad) lo cual no parece correcto, pero de todos modos lo aprobé. –