Questions tagged [alloc]
207 questions
6
votes
7 answers
iOS error: No visible @interface for 'xxxx' declares the selector 'alloc'
Here is my TextValidator class:
//TextValidator.h
#import
@interface TextValidator : NSObject
- (BOOL) isValidPassword:(NSString *)checkPassword;
- (BOOL) isValidEmail:(NSString *)checkString;
- (BOOL) isEmpty:(NSString…

ankakusu
- 1,738
- 8
- 26
- 37
6
votes
2 answers
Creating a singleton with allocWithZone:
BNRItemStore is a singleton, and I was confused on why super allocWithZone: must be called instead of plain old super alloc. And then override alloc instead of allocWithZone.
#import "BNRItemStore.h"
@implementation BNRItemStore
+(BNRItemStore…

stumped
- 3,235
- 7
- 43
- 76
5
votes
2 answers
Objective C when to use alloc and when not to
I'm trying to learn objective C and one of the things i find very weird to follow is when to use alloc and when not to. Take for instance this snip of code:
NSURL *url =[NSURL URLWithString:@"http://www.apple.com"];
Why don't you have to do…

gcoleman0828
- 1,541
- 3
- 30
- 49
5
votes
0 answers
Erlang, pass an nif object between functions
I write a C nif code and in function new, it creates a stack struct with enif_alloc_resource and returns that. when i use function enif_make_resources, it always returns <<>> in erlang.
Here is my C code:
#include "erl_nif.h"
static…

Amin
- 755
- 6
- 21
5
votes
2 answers
How to allocate array of IntPtr [] in unmanaged memory?
To allocate memory in managed code i use:
IntPtr [] params_list_n = new IntPtr [5];
But for unmanaged memory i use Marshal.AllocHGlobal
And I do not understand how, in this case to allocate memory for the array.
Ideally I want to use the function…

Mixer
- 1,292
- 3
- 22
- 41
4
votes
2 answers
initialization discards ‘const’ qualifier from pointer target type
I have an array structs that hold char names. I want to sort them alphabetically using qsort however I keep getting an error message saying "initialization discards ‘const’ qualifier from pointer target type". I believe my cmpmi() function and qsort…

collegecoder
- 41
- 4
4
votes
4 answers
Need help understanding a specific alloc/release idiom in iOS/Objective-C programming
I'm an experienced C/C++ programmer starting to learn Objective-C development. I'm currently looking through the UICatalog sample and came across another instance of an idiom I've seen several places and never understood.…

Will McLafferty
- 61
- 1
- 2
4
votes
1 answer
why terminate called after throwing an instance of 'std::bad_alloc'?
Every 1 second, function works.
my system the linux.
Runs suddenly dies.
-----global-------
static int arrayNum[33000];
-------------------
function(){
unsigned short int** US_INT;
US_INT= new unsigned short int*[255];
…

OMG_Soruce
- 96
- 1
- 2
- 9
4
votes
2 answers
Linked list in allocated space?
I hope this question won't be weighted too much on discussion but on a clear answer.
I learned C at university and just started to write my first useful program (meaning without a specification). I just stumbled upon an issue which I hadn't dealt…

Philipp Murry
- 1,660
- 9
- 13
4
votes
2 answers
Is this use of realloc correct?
Original question
Can I use realloc() function like the following code:
int *ptr, i, num=5;
for (i=0; i

synth
- 65
- 5
4
votes
4 answers
How do I know how much memory to realloc?
I have one question regarding design of my application.
Here's the pseudo code:
char* buffer_to_be_filled = (char*) malloc(somesize);
fill_the_buffer(buffer_to_be_filled);
free(buffer_to_be_filled);
The problem is that I don't know how much size…

Jan Vorcak
- 19,261
- 14
- 54
- 90
4
votes
2 answers
What is best practice for new NSObject - alloc / init or change existing?
I would like to get some opinion about best practice in iOS5 and higher (ARC enabled). For example, I have a database with cars - image, name, max speed, etc. info. In app I have to show a car with info, then, after user interaction - next car, then…

valdistt
- 184
- 7
4
votes
3 answers
Which increases the retain count: alloc or init?
When we need create an object and take ownership of it we write
NSObject *someObject = [[NSObject alloc] init];
After that someObject's retain count will be equal to 1. Which method increases the count, alloc or init, and where in Apple's docs is…

Rostyslav Druzhchenko
- 3,673
- 3
- 33
- 38
3
votes
1 answer
Why does Rust std::alloc allocate with larger than expected gaps?
If I were to make two allocs using an example layout with size 256 and alignment 1024, I would expect the second allocation to be at the first multiple of 1024 after the first (ie ptr2 - ptr1 == 1024). Instead I am finding that there is a gap twice…

Niland Schumacher
- 31
- 4
3
votes
2 answers
initWithContentsOfFile:path] memory management when returns nil
[[UIImage alloc] initWithContentsOfFile:path]
return nil when the method can't initialize the image. Then next code is not releasing the allocated UIImage, as image is nil in the [image release] line:
UIImage* image = [[UIImage alloc]…

Isidoro Aguilera
- 31
- 3