Skip to content

-[NSData initWithBytesNoCopy: length: freeWhenDone:] #3

@xcvista

Description

@xcvista

You can use -[NSData initWithBytesNoCopy: length: freeWhenDone:] method to avoid an unneeded memory copy and free(), like the following.

- (id)initWithBase64String:(NSString *)aString
{
    NSData *data = [aString dataUsingEncoding:NSASCIIStringEncoding];
    size_t outputLength;
    void *outputBuffer = NewBase64Decode([data bytes], [data length], &outputLength);
    return [self initWithBytesNoCopy:outputBuffer length:outputLength freeWhenDone:YES];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions