Questions tagged [allocation]

Memory allocation is an operation of giving a program a block of memory.

1869 questions
0
votes
1 answer

C dynamic allocation with realloc of a char**

I'm new here and don't speak very well english. I've a question concerning my code (in C). What the code should do: There exists a file named "g.txt", that should be opened. Then it reads it line by line and copies each line in a buffer…
0
votes
2 answers

Julia memory allocation in simple size statement

I am running the following routine in with --track-allocation=user. The routine is called in a for loop. Still I am surprised at the allocation generated in the first line: I would expect numqps to be allocated on the stack and thus not contributing…
krcools
  • 897
  • 5
  • 12
0
votes
1 answer

Using set_intersection with dynamic allocation?

I'm reading about set_intersection and it appears to expect the user to allocate the correct amount of space (or more) in advance but isn't that strange? In c++ you often use std::vector which dynamically allocates space on the go. Why would…
AturSams
  • 7,568
  • 18
  • 64
  • 98
0
votes
1 answer

Trying to catch a failed allocation inside of a recursive function: Unhandled exception/Stack overflow

This is a problem I'm trying to solve for a school assignment. I've created a single linked list class that contains a Node(ie. a struct that holds a character "item", and a Node pointer "next") and a Node pointer head. As specified by the…
b1skit
  • 327
  • 4
  • 16
0
votes
6 answers

C++: What does it mean to "new" a collection that will keep growing?

I am new to C++. What does it mean exactly to "new" a collection? For example: UnicodeStringList* tmp = new UnicodeStringList; // where UnicodeStringList is typedef to std::list When you "new" something you have to know exactly how…
jbu
  • 15,831
  • 29
  • 82
  • 105
0
votes
1 answer

Do you need to free a struct pointer before setting it to a new value?

I have a struct: struct Foo { int x; int *ptr; void *ptr2; }; If I allocate memory for ptr using: ptr = malloc(sizeof(int)); and later I want to it to point it to something else…
user1224478
  • 345
  • 2
  • 5
  • 15
0
votes
0 answers

Matlab preallocating arrays when final array-size is unknown

I am running a matlab script that extracts data and saves them in variables based upon variable input - see code below: folder = 'Raw/'; fileStart = 'DAT_MT_'; fileMiddle = '_M1_'; fileEnd = '.csv'; years = cellstr(years); price = zeros(0,1); date…
Benvaulter
  • 249
  • 1
  • 5
  • 14
0
votes
3 answers

Memory allocated was not freed for some reason - C

I am currently writing a chess game in C as a project in my studies. I checked memory leaks with valgrind and found a few leaks. I examined the log of the valgrind test and found that there is always the same chain of functions in every leak that…
BK Tomer
  • 107
  • 2
  • 11
0
votes
1 answer

RenderScript one input- and two output-Allocations

I managed to write a Kernel that transforms an input-Bitmap to a float[] of Sobel gradients (two separate Kernels for SobelX and SobelY). I did this by assigning the input-Bitmap as a global variable and then passing the Kernel based on the Output…
Settembrini
  • 1,366
  • 3
  • 20
  • 32
0
votes
1 answer

What is the better way of handling temporary strings?

I have a situation where I need to use some strings temporarily but I've read so many conflicting things that I'm a bit confused as to what the best way to proceed is. I need to assign some strings inside an if structure but use them outside the if…
Spider-Paddy
  • 303
  • 2
  • 14
0
votes
1 answer

Allocate more than 512mb ram on android

I'm writing a litte android app which fills the ram of a device for testing purposes. But I'm not allowed to allocate more than 512MB. The error log says: Throwing OutOfMemoryError "Failed to allocate a 1000012 byte allocation with 229520 free…
Fabian
  • 2,693
  • 2
  • 21
  • 33
0
votes
0 answers

iOS: Debugging memory leaks for UILabel in swift

I new to profiling and using instruments in xcode. I am facing of problem of memory leaks in tableViewCell for UILabel(CALayer). In my code all the tableViewCell have a fixed view called bottomView. This bottomView may or may not contain UILabel…
meteors
  • 1,747
  • 3
  • 20
  • 40
0
votes
1 answer

Unexpected behavior with sprintf

I am writing a program and I have a very weird issue. char *abs_alg *iterator *test_case; sprintf(abs_alg, "%s/data_root/projects/PROJ-%s/proj/src/%sAbsAlgorithm.cpp", getenv(ALGATOR_ROOT), argv[2], argv[2]); sprintf(iterator,…
golobitch
  • 1,466
  • 3
  • 19
  • 38
0
votes
3 answers

Proper way to have two pointers point to the same memory chunk

I have a structure: struct generic_attribute{ int current_value; int previous_value; }; And a constructor which outputs a pointer to this structure: struct generic_attribute* construct_generic_attribute(int current_value){ struct…
RebeccaK375
  • 871
  • 3
  • 17
  • 28
0
votes
1 answer

Issues with pascal triangle and dynamic memory allocation, c

I'm writing a code for my C programming class and stumbled upon a problem. I'm supposed to write a program which will show as an output Pascal's triangle. I'm to use 1d arrays and in each iteration make the array bigger by using realloc. The trouble…
ninigi
  • 143
  • 1
  • 3
  • 14