dynamic-memory-allocation Questions

7

Solved

I stumbled upon a quiz that involved array declaration with different sizes. The first thing that came to my mind is that I would need to use dynamic allocation with the new command, like this: wh...
Electrothermics asked 20/1, 2020 at 10:2

6

I wrote a simple example: #include <iostream> int main() { void* byte1 = ::operator new(1); void* byte2 = ::operator new(1); void* byte3 = malloc(1); std::cout << "byte1: " <&l...
Sportive asked 29/11, 2019 at 2:58

1

Solved

In C++ when joining a bunch of strings (where each element's size is known roughly), it's common to pre-allocate memory to avoid multiple re-allocations and moves: std::vector<std::string> w...
Incident asked 29/10, 2019 at 16:6

3

After watching CppCons Will Your Code Survive the Attack of the Zombie Pointers? I'm a bit confused about pointer lifetime and need some clarification. First some basic understanding. Please corre...
Biogenesis asked 16/10, 2019 at 13:17

2

Solved

Suppose I have something like: real, dimension(:), allocatable :: S integer, dimension(:) :: idx ... S = S(idx) where S and idx are properly allocated/initialized before the assignment. What do...
Inane asked 22/8, 2019 at 9:29

1

Solved

My question is about the logic of dynamic memory allocation in assembly (particularly, MASM). There are lot of articles on this topic and all of them rely on the use of malloc or brk. However, acco...

3

Solved

I'm currently in the process of building an embedded system, using an ARM Cortex M3 processor, with 64 KB of SRAM. At the moment, I'm looking for a way to ensure deterministic performance with STL ...

3

I have been working on the following code for a while and there is a problem when I tried to allocate/deallocate memory for a struct and its elements. Any insights into the problem would be greatly...
Reames asked 10/5, 2019 at 6:42

2

Solved

I'm reading this book: "C von A bis Z". There is this example. /* ptr14.c */ #include <stdio.h> #include <stdlib.h> #include <string.h> /* Fehler: Funktion gibt die Adresse * e...
Insignificant asked 1/4, 2019 at 7:29

3

I am observing the following behavior in my test program: I am doing malloc() for 1 MB and then free() it after sleep(10). I am doing this five times. I am observing memory consumption in top whil...
Pseudo asked 22/3, 2019 at 7:45

6

Solved

Well, I can't understand when and why it is needed to allocate memory using malloc. Here is my code: #include <stdlib.h> int main(int argc, const char *argv[]) { typedef struct { char *na...
Anderaanderea asked 10/1, 2012 at 8:40

2

new int[0] is permitted in C++ but is std::allocator<int>().allocate(0) well defined? More general, must all Allocators accept 0 as a parameter to allocate? Edit: After reading the answers I...

0

This question is similar to this but there was no answer. I am trying to enable dynamic allocation in Spark in YARN mode. I have 11 node cluster with 1 master node and 10 worker nodes. I am follow...
Diverticulum asked 24/11, 2018 at 12:40

2

Solved

I have a pointer array (ptrArr1) with two elements. I want the pointer array to be dynamically allocated. I can assign an address to the first element of the pointer array just fine, but I do not k...
Lakieshalakin asked 20/11, 2018 at 7:55

1

Solved

I want to store a program state in a file. So I have a mmapped file that I perform operations on and then save it and maybe use it later. This is fine for simple things but if I want a long lived ...
Arriola asked 19/10, 2018 at 15:34

2

Solved

I'm sorry to ask another newbie question, but google could'nt quite help me (or maybe I just didn't understand it). I'm trying to code a class that is capable of storing some simple connection dat...
Inject asked 16/9, 2018 at 18:8

1

Solved

I was reading a question on SO and in one of the answers, it has been mentioned as: If no unambiguous matching deallocation function can be found, propagating the exception does not cause the o...

3

Solved

From LukeH's answer to what is the max limit of data into list<string> in c#? The maximum number of elements that can be stored in the current implementation of List is, theoretically, Int32...
Transarctic asked 7/7, 2018 at 22:58

1

I am amazed that I can't find any document stating the difference between _int_malloc and malloc in the output of Valgrind's callgrind tool. Could anybody explain what's their difference? Furthe...

2

#include <stdlib.h> void *operator new[](size_t size, int n){ if( size != 0 && n != 0 ) return calloc(n, size); return calloc(1, 1); } int main(){ int * p1; const int i = 0; ...
Calistacalisthenics asked 30/4, 2018 at 18:8

1

Solved

Consider the code auto p = new T( U(std::move(v)) ); The initializer is then U(std::move(v)). Let's assume that T( U(std::move(v)) ) does not throw. If the initializer is evaluated after the und...

1

Solved

Since a couple of years ago or so I was completely new to Fortran, I overused SUBROUTINEs with no arguments, together with shared data, so that these procedures have made calculations on the actual...

2

Solved

Pedantically, this may not be OK. As per cppref: If expression is anything else, including if it is a pointer obtained by the array form of new-expression, the behavior is undefined. Putting t...

10

New to C, thanks a lot for help. Is it possible to define an array in C without either specifying its size or initializing it. For example, can I prompt a user to enter numbers and store them in...
Comply asked 20/10, 2009 at 1:20

11

Solved

This document says std::list is inefficient: std::list is an extremely inefficient class that is rarely useful. It performs a heap allocation for every element inserted into it, thus having an e...

© 2022 - 2024 — McMap. All rights reserved.