Memory allocation is an operation of giving a program a block of memory.
Questions tagged [allocation]
1869 questions
28
votes
4 answers
Why doesn't `Box::new` return an `Option` or `Result`?
I don't understand why Box::new doesn't return an Option or Result.
The allocation can fail because memory is not unlimited, or something else could happen; what is the behavior in such cases? I can't find any information about it.

Stargateur
- 24,473
- 8
- 65
- 91
28
votes
8 answers
What happens when you deallocate a pointer twice or more in C++?
int main() {
Employee *e = new Employee();
delete e;
delete e;
...
delete e;
return 0;
}

flopex
- 434
- 3
- 6
- 11
28
votes
8 answers
checking for NULL before calling free
Many C code freeing pointers calls:
if (p)
free(p);
But why? I thought C standard say the free function doesn't do anything given a NULL pointer. So why another explicit check?

zaharpopov
- 16,882
- 23
- 75
- 93
27
votes
3 answers
Malloc error "can't allocate region" failed with error code 12. Any idea how to resolve this?
i am getting this error and dont know what to do with that:
AppName(3786,0xa0810540) malloc: *** mmap(size=16777216) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
If i set a breakpoint…

brush51
- 5,691
- 6
- 39
- 73
25
votes
1 answer
What is a NSPathStore2?
All that I know is this:
Its private
Its created somehow cause of strings trying to do Path related things
I mean, if they are private and still my app is telling me that NSPathStore2 is interfering, I need to know why. I just want to understand…

CalixJumi
- 367
- 3
- 12
25
votes
3 answers
What is the largest amount of memory I can allocate on my MacBook Pro?
I'm trying to figure out how much memory I can allocate before the allocation will fail.
This simple C++ code allocates a buffer (of size 1024 bytes), assigns to the last five characters of the buffer, reports, and then deletes the buffer. It then…

Thomas Jay Rush
- 401
- 4
- 12
25
votes
2 answers
malloc(sizeof(int)) vs malloc(sizeof(int *)) vs (int *)malloc(sizeof(int))
I acknowledge that all three of these have a different meaning. But, I don't understand on what particular instances would each of these apply. Can anyone share an example for each of these? Thank you.
malloc(sizeof(int))
…

rajagrawal
- 622
- 4
- 14
- 26
24
votes
5 answers
How to implement a memory heap
Wasn't exactly sure how to phrase the title, but the question is:
I've heard of programmers allocating a large section of contiguous memory at the start of a program and then dealing it out as necessary. This is, in contrast to simply going to the…

Prime
- 4,081
- 9
- 47
- 64
24
votes
11 answers
C++ Multi-dimensional Arrays on the Heap
How would I go about dynamically allocating a multi-dimensional array?

eplawless
- 4,225
- 7
- 34
- 35
24
votes
5 answers
Passing around fixed-size arrays in C++?
Basically I'd like to do something like that:
int[3] array_func()
{
return {1,1,1};
}
int main(int argc,char * argv[])
{
int[3] point=array_func();
}
But that doesn't seem legal in C++. I know I can use vectors, but since I know the size…

static_rtti
- 53,760
- 47
- 136
- 192
21
votes
1 answer
Correct way to cap Mathematica memory use?
Under a 32-bit operating system, where maximum memory allocated to any one program is limited, Mathematica gracefully terminates the kernel and returns a max memory allocation error.
On a 64-bit OS however, Mathematica will freely use all the memory…

Mr.Wizard
- 24,179
- 5
- 44
- 125
21
votes
8 answers
What's a good C memory allocator for embedded systems?
I have an single threaded, embedded application that allocates and deallocates lots and lots of small blocks (32-64b). The perfect scenario for a cache based allocator. And although I could TRY to write one it'll likely be a waste of time, and not…

Robert Gould
- 68,773
- 61
- 187
- 272
18
votes
3 answers
Reservation allocation algorithm
I am looking for algorithms for allocating reservations to resources. This could be Hotel reservations matched to available rooms - Meeting reservations matched to available meeting rooms - Restaurant reservations matched to tables.
What they have…

Lemmedaskeren
- 181
- 1
- 1
- 3
18
votes
3 answers
Why use [ClassName alloc] instead of [[self class] alloc]?
I'm reading through Mark Dalrymple's Learn Objective-C on the Mac (only at the chapter on Protocols, so still relatively newbish) and trying to figure something out:
Why would you ever reference a class by its own name? If I had a class called Foo,…

Nick Sweet
- 2,030
- 3
- 31
- 48
18
votes
4 answers
How to preallocate(reserve) a priority_queue?
How can I preallocate a std::priority_queue with a container of type std::vector?
std::priority_queue> pq;
pq.c.reserve(1024);
Does not compile because the underlying vector is a protected member.
Is it…

Boyko Perfanov
- 3,007
- 18
- 34