Skip to main content

Questions tagged [dynamic-memory-allocation]

Dynamic memory allocation, usually in the context of languages without garbage collection or mandatory or automatic reference counting, refers to the process or asking the operating system for a variable sized block of memory.

dynamic-memory-allocation
Filter by
Sorted by
Tagged with
0 votes
1 answer
59 views

Segmentation fault on copy custom dynamic array [duplicate]

I'm trying to implement my custom dynamic array, like std::vector. Dynamic array module code: #ifndef ARRAY_H #define ARRAY_H #include <cstdlib> #define CAPACITY_SCALE_FACTOR 2 template <...
vipe4ka-visko4ka's user avatar
0 votes
0 answers
36 views

How do I dynamically allocate memory for a multidimentional array in C? [duplicate]

Dynamically allocate memory for a multidimensional array (matrix) with a specified number of rows and columns. How to allocate memory? How to allocate memory for 2D array? How to dynamically allocate ...
Samhitha Harini's user avatar
0 votes
0 answers
10 views

How to Comparing Custom Malloc Package (CMU Malloc) with Standard Allocators Using Benchmarks

I am currently working on the CMU Malloc Lab and I have implemented my own malloc package in mm.c. I would like to benchmark my implementation not only with the Malloc Lab grading script but also ...
Kim TaeHyeon's user avatar
0 votes
1 answer
26 views

Why in Xcode debugger and instruments some memory is just "malloc(48 bytes)"

This, but meanwhile, other objects have fully qualified ObjectiveC class names, Swift class names, etc. Why are some allocations written as "malloc(48 bytes)", while others aren't? Does this ...
Isaaс Weisberg's user avatar
0 votes
1 answer
82 views

How can I prevent newly added users from having their age increased in the same iteration in a linked list in C?

I'm creating a Linked List of Users where one of the field is int age; The user can choose from several options (addUser, findUser, exit, etc.) on each iteration of the while loop I want to increase ...
CStudent's user avatar
  • 156
0 votes
1 answer
30 views

Does Spark 3.X on kubernetes supports dynamic allocation

We are using EKS master as spark master and as of now we are using fixed number of executors. Now we want to enable dynamic allocation, does it supports in case of EKS. I've seen some blogs saying to ...
Rajashekhar Meesala's user avatar
0 votes
1 answer
80 views

Why Can't I Successfully Allocate Space for a 1D Array Anywhere Besides Main? [duplicate]

I'm working with my professor's code that makes a list of 30 random numbers, and it started throwing errors when I tried to run it. I noticed that when I printed out the array contents within the ...
spookikitti's user avatar
0 votes
1 answer
57 views

Segfault with memcpy and array

I'm learning C and just ironing out my understanding of how memory is allocated. I'm playing around with the following code and it's segfaulting but I'm not sure why. Any pointers? (no pun intended) #...
testing09's user avatar
  • 127
0 votes
2 answers
54 views

Why can't I reassign flexible array member?

I have the following struct with a flexible array member. However, the code does not compile: #define INITIAL_CAPACITY 5 typedef struct Object { int size; int elements[]; } Object; int main(...
testing09's user avatar
  • 127
1 vote
1 answer
49 views

Segmentation fault in using recursive selection sort in C language

I have i have wrote a C program. It should use recursive selection sort but segmentation fault occurs for big input (10000 or more). Debugger says that the segfault happens in findim function, but it'...
Giuseppe Guerrini's user avatar
2 votes
1 answer
84 views

Does redim use the heap or the stack memory in VBA?

I know this is quite strange to ask for a language that is far from a low-level language such as C and C++, but it caught my attention that for example if I do this: Dim tempArray(0 To 2) As Integer ...
Isaias's user avatar
  • 63
2 votes
2 answers
124 views

Unexpected result of string concatenation in C

The following C program should append an "/" after the path received in argv if the argument does not end in "/". The "odd for me" behavior is that after the first ...
Eduard's user avatar
  • 43
0 votes
1 answer
64 views

How to default initialise non-POD object onto same address?

tl;dr; How can one make every instance of object have same constant address, and then assign it after user wants to change it? I have a need to develop my own NULL (ish) objects, and would like to ...
Danilo's user avatar
  • 1,021
7 votes
1 answer
138 views

What will happen if I call `allocate_at_least(0)` according to C++23 standard?

As shown here, the behavior of allocate(0) is unspecified. So, what will happen if I call allocate_at_least(0) according to C++23 standard? Is the behavior implementation-defined, or will it be ...
yqZhang4480's user avatar
0 votes
0 answers
55 views

Unexpected double free in single linked list

`I am trying to do a simple linked list. Everything works fine, but after the program calls ~List() I am getting "double free in tcache2" and SIGABRT every time I run the program and ...
Juliusz Bednarek's user avatar
0 votes
0 answers
22 views

Why does console.time/performance.measure and memory inspector don't have similar values

I'm trying to make an application that measures the times of loops with different data This is example for memory inspector vs console.time: Any advice or criticism is welcome from how to improve the ...
Aleksa Kovacevic's user avatar
0 votes
1 answer
33 views

File open problems in C

I'm coding a Priority Scheduling Algorithm on C and I have some problems with Opening a File. My laptop is M1 macbook and My Programming environment is vscode. This program is work on Terminal, but it'...
권기범's user avatar
-1 votes
1 answer
62 views

Reduce time for allocating a c++ 2D vector

The question is fairly simple. For this single line in c++, std::vector<std::vector<double>> x_vec(10, std::vector<double>(2)); where I create a vector of size (10, 2) to be ...
John 's user avatar
  • 29
0 votes
1 answer
41 views

valgrind shows memory leak in my program in c (two versions)

int main() { double (*arr)[COLS] = (double*)malloc(sizeof(*arr) * ROWS); assert(arr!= NULL); for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) {...
Κώστας Κατσάκος's user avatar
-1 votes
1 answer
85 views

How to handle & fix Garbage Data?

Problem state I have a template class called Group which can access unauthorized places in memory. The member variable Group<T>::Items points to serine of locations on the heap that stores a ...
Mohmmed Omer's user avatar
1 vote
1 answer
25 views

Is it possible to determine whether and address was obtained using sbrk or mmap?

I am developing a heap memory allocator based on Hoard for educational purposes. I know how to allocate memory using sbrk and mmap and have developed toy level allocators before. I want to use mmap ...
Borisav Živanović's user avatar
0 votes
1 answer
40 views

Problem with assigning value to reallocated dynamic array - maze solver

I am struggling with storing value to dynamic array, which was reallocated by realloc() function. I am creating maze solver program and as a inner representation I want to create 1D array tile_array ...
Loosos's user avatar
  • 85
0 votes
0 answers
34 views

This MPI_Gatherv code not working and I don't know why

I wrote this code in C that multiplies a matrix by a vector, locally in each process(ylocal) and then the root process gathers the results in its local vector(y). I am using MPI_Gatherv because it has ...
Nementh's user avatar
0 votes
1 answer
52 views

Freeing memory for dynamically allocated hashmap with structs as values - C

I have followed a few tutorials for hashmaps in c. From the code you can probably tell I relied heavily on this implementation which has a nice follow up video where he revisits it to show how he ...
Surfytom's user avatar
1 vote
1 answer
88 views

realloc(): invalid old size and Aborted (core dumped) when using realloc and free in a while loop

I am working on a program that uses a linked list implemented as typedef struct Node{ char* word; int freq; struct Node *next; }Node; typedef struct { Node* head; }LL; and have ...
The-coder-E's user avatar
1 vote
2 answers
94 views

Why do we unmap memory right after copying to it

Why do we unmap memory rigth after mapping it? Isn't it that we are holding data in this address? void* data; vkMapMemory(device, stagingBufferMemory, 0, imageSize, 0, &data); memcpy(data, pixels, ...
Ciborg's user avatar
  • 25
1 vote
0 answers
31 views

How does one free memory in the heap in risc-v assembly? [duplicate]

I am currently studying risc-v assembly and started to research more about the heap. In the current problem I'm solving, I'm creating a linked list by allocating space on the heap with a syscall and ...
Andrey Cortez's user avatar
1 vote
0 answers
76 views

Are allocatable derived type components just pointers for GNU compiler?

Consider the following minimal example: program prog type node integer::val type(node),allocatable::next end type type(node)::a,b allocate(a%next) a%val=1 a%...
V T's user avatar
  • 133
1 vote
1 answer
113 views

Right way to allocate type instances containing pointers in Fortran

Consider the following minimal example: module lib private type node integer::val type(node),allocatable::next end type type,public::list integer::num=0 ...
V T's user avatar
  • 133
1 vote
1 answer
69 views

How to avoid reallocating an array of pointers when we dont know the exact size from start

Im trying to design a binary tree like data-struct except there is no limit on children each node can have. Now within each node I can declare node struct as such: struct node { int id; int ...
JJ Adams's user avatar
  • 503
-1 votes
1 answer
61 views

Memory Allocation function is not working properly [closed]

My function is not working properly. For example, when I try to add resistor called R1 with the value of 500, and then R2 with the value of 500, and then R1 with the value of 500 again, it gives me ...
Alya Bayer's user avatar
1 vote
2 answers
50 views

Variable doesn't get updated when I run a loop [closed]

I want to iterate through a word and print each of its characters, together with its ASCII number. I've tried #include <iostream> #include <stdio.h> using std::cout; int main() { ...
Elizabeth Middleford's user avatar
0 votes
1 answer
83 views

C Changing value of array of struct through reference

I asked a similar question before, when I didnt know what was the problem of my code. Just as I was recommended I will give it in a better format. This is an example of what happens to my code. #...
Acaymo Sánchez Ramirez's user avatar
1 vote
1 answer
42 views

What is wrong with this Reflection.Emit for value conversion delegates?

Sorry for this long question but I feel I have to provide a bit more background as my issue is very specific. Bigger picture I am developing on a Unity tool to be used specifically for Embedded Linux ...
derHugo's user avatar
  • 88.6k
0 votes
2 answers
23 views

What are the differences between using vector and using new,delete in c++?

I would like to ask about the difference between using vector and using new, delete in C++. Both new, delete and malloc, free are used for dynamic memory allocation. So why don't we just use vector, ...
Tim's user avatar
  • 3
1 vote
1 answer
63 views

Find the some smallest negative using Dynamic memory allocation in C

I'm doing my homework but there is some bugs I cannot fix Could you please help me? The question is using Dynamic memory allocation in C Find the some location of smallest negative element The ...
Đinh Trọng Đạt's user avatar
0 votes
1 answer
71 views

Access violation after reallocating memory

I get access violation if I'm allocating memory to list->v[list->length] #include <string.h> #include <stdio.h> #include <stdlib.h> typedef struct { char* denumire, * ...
Eduard Şubredu's user avatar
0 votes
0 answers
21 views

Why using a pointer of a self-defined structure in the CS50 Inheritance problem

Hi here is the link of the homework description. And here is the part of the code that's relevant: typedef struct person { struct person *parents[2]; char alleles[2]; } person; const int GENERATIONS =...
Scarlett's user avatar
0 votes
0 answers
20 views

How to read the amount of memory block consumed by pointer? [duplicate]

There is a creation of a global accessible structure as: struct dummy1 { int data1; int data2[10]; } DATA_STORE_A; struct dummy2 { int data1; int data2[10]; int extended_data[20]; } DATA_STORE_B; ...
Gahan's user avatar
  • 4,173
1 vote
3 answers
87 views

Return string (or char *) from a C function

I need a function to return a string of various sizes. Here is my code: #include <stdio.h> #include <string.h> #include <stdlib.h> char *get_option_argument(char *arg, char *...
jean faure's user avatar
2 votes
1 answer
66 views

How to define different [global_allocator]s for a monolithic os kernel and its applications

We're currently working on a monolithic operating system (x86) in Rust. Our cargo workspace looks roughly like this: project dir |--src (contains all kernel related code, omitted here) | |--main.rs | ...
ebeneEinHalb's user avatar
0 votes
1 answer
37 views

why can i not free ctypes memory in c?

i have a python file that trys to free memory from an array created using ctypes: import ctypes import os # Load the DLL script_dir = os.path.dirname(os.path.abspath(__file__)) dll_path = os.path....
NiceGuySaysHi's user avatar
0 votes
1 answer
84 views

Problem with reallocating array during runtime in Cpp

I am trying to create an array data structure in C++ using classes. The idea is that the array has a predefined length to it and whenever there is need for extra space, the array gets reallocated to ...
Dev_A's user avatar
  • 11
0 votes
0 answers
39 views

Valgrind showing invalid read of size 4 when using an erase function [duplicate]

So I am writing an assignment that utilizes a vector class that I had to make that mimics the standard Vector file for c++. In my program, I am trying to filter intervals for showing more than once. ...
Howlkipsure139's user avatar
0 votes
1 answer
80 views

Byte array and int transferring between C# and C++ in Unity DLL Integration

I am developing a Unity project where I've created a DLL in C++ to integrate with my C# scripts. The C++ function I've written is meant to receive a byte array and its size as input parameters. ...
Lucas B's user avatar
0 votes
0 answers
96 views

How to check if the requested memory chunk can be allocated?

I'm working on a C++ project where I want to utilize the TLSF (Two-Level Segregated Fit) allocator for managing memory allocations. Specifically, I need to implement a method, CanAllocate, which ...
Aram's user avatar
  • 1
-4 votes
1 answer
91 views

C-Dynamic Memory Allocation

typedef struct { double x; double y; } point; point p1; point* p2 = malloc(sizeof(point)); In this code where the variables p1,p2,p1.x, and p2->x are stored in stack or heap memory? Where ...
Suthekshan 's user avatar
1 vote
2 answers
79 views

Is it possible to write on memory that was moved away using memmove in C?

I'm sorry if my code is garbage but I wanted to experiment with string manipulation on an already dynamically allocated string without losing my original pointer so that when I do go ahead and free up ...
Lenny_Medina's user avatar
1 vote
1 answer
101 views

What's the reason for the occurrence of Segmentation fault (core dumped)?

I use C language, and apply Dynamic Programming to solve the Travelling salesman problem. There is such a problem on ZeroJudge, An Online Judge System For Beginners, but I get Segmentation fault (core ...
Eric's user avatar
  • 13
1 vote
0 answers
81 views

C++ templates: choice between static and dynamic allocations (a la Eigen)

Eigen, the linear algebra library written in C++, uses a clever technique: template parameters (for example the dimensions of a matrix) that are not known at compile time can take the special value ...
Charlie Vanaret's user avatar

1
2 3 4 5
73