dynamic-memory-allocation Questions
2
Solved
I was wondering if an implementation of std::variant must necessarily be "flat" or whether it is allowed to dynamically allocate memory for its members, such that a sequence of variants would degen...
Shriner asked 18/12, 2017 at 20:36
3
Solved
I researched a lot of static and dynamic memory allocation but still, there is a confusion that:
int n, i, j;
printf("Please enter the number of elements you want to enter:\t");
scanf("%d", &n...
Instal asked 12/12, 2017 at 21:30
2
I have a question about dynamic memory allocation.
Context: I'm writing a program that reads a text file of words and counts the frequency with which each word occurs (one word per line).
This p...
Kaz asked 4/12, 2017 at 2:4
2
Solved
I need to take a file that is inputted by the user and multiply it by another file. That much I know how to do.
The problem is one file is an array and the other is a matrix.
I need to scan in t...
Encasement asked 11/11, 2017 at 4:43
4
Solved
I'd like to create a class Word, which houses a word. I'll have an instance of the class for pretty much every word in the dictionary (so lots) -- and no, I cannot use a tree structure to store thi...
Intarsia asked 16/10, 2017 at 12:12
2
Solved
If we write something like:
int *arr = new int[5];
In this case, the system dynamically allocates space for 5 elements of type int and returns a pointer to the first element of the sequence.
Bu...
Facia asked 13/10, 2017 at 6:41
2
Solved
A few times I've stumbled across the scenario where I have a container of pointers that needs to be copied.
Let's say we have the following class hierarchy:
Student (base class)
Freshman (subc...
Carin asked 10/10, 2017 at 15:15
2
Solved
Consider this simple example:
#include <algorithm>
#include <iostream>
#include <list>
#include <numeric>
#include <random>
#include <vector>
#include <itera...
Earthshaking asked 18/6, 2015 at 14:38
8
Is this legal to do? Can you assign ptr to something after it has been freed?
int * ptr = (int*) malloc(sizeof(int));
free(ptr);
ptr = (int *) malloc(sizeof(int));
Abshire asked 22/8, 2017 at 6:17
4
Solved
I am working on a single producer single consumer ring buffer implementation.I have two requirements:
Align a single heap allocated instance of a ring buffer to a cache line.
Align a field within ...
Byrle asked 26/12, 2013 at 21:21
4
I am trying to dynamically allocate memory into the heap and then assign values in those memory addresses. I understand how to allocate the memory but how would I assign for example the value in a ...
Gefen asked 23/3, 2014 at 2:59
7
Solved
I would like to know what is the difference between static memory allocation and dynamic memory allocation?
Could you explain this with any example?
Hawkie asked 5/12, 2011 at 12:30
4
Solved
I just started working with C++ and now I have a really basic question.
I wrote 2 classes:
Coordinate:
#include <stdio.h>
class Coordinate {
private:
int x;
int y;
public:
Coordinate(i...
Streak asked 20/3, 2017 at 17:48
1
Solved
I just started programming and have a beginner question, I want to write a function to read a file with unknown length line by line. Since I wouldn't know the length of each line so I used getline(...
Subarctic asked 27/2, 2017 at 6:6
4
I am trying to understand inners of double pointer (which is pointer holding another pointer) to form an array of pointers. So, I am trying to run the following code by experimenting on mallo...
Overplus asked 24/2, 2017 at 9:4
4
Solved
I want to determine what is the maximum limit of memory I can allocate in my computer. This is the code that I have written for this task:
#include <stdio.h>
#include <stdlib.h>
int m...
Hayrick asked 15/2, 2017 at 9:35
4
So my code is this :
int a, b;
printf("Give dimensions\n");
scanf("%d %d", &a, &b);
double array1[a][b];
printf("Give values\n");
int i, j;
for(i=0; i<a; i++)
{
for(j=0; j<b; j++)
...
Verbosity asked 19/1, 2017 at 14:11
4
Consider the following C code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int arrSize;
scanf("%d", &arrSize);
printf("%d\n",arrSize);
in...
Ephemera asked 2/1, 2017 at 7:52
5
I have just learned about the C calloc() function the other day. Having read its description and how it differs from malloc (1, 2), I get the idea that, as a non-embedded programmer, I should alway...
Patron asked 21/12, 2016 at 13:4
3
Solved
To be clear, my code works perfectly. The issue that concerns me is that i am unsure of my array allocation type.
My task is rather simple: i am required to do some operations within a dynamically...
Neuron asked 21/12, 2016 at 15:18
4
Solved
I was solving some programming exercise when I realised that I have a big misunderstanding about pointers. Please could someone explain the reason that this code causes a crash in C++.
#include &...
Gobetween asked 16/12, 2016 at 12:8
3
In glibc, malloc is implemented with arenas.
So, for example, it is possible that the memory first allocated by malloc and later freed in thread A can not be used by another call of malloc in thre...
Sammysamoan asked 4/7, 2015 at 23:12
2
Solved
I'm implementing combsort. I'd like to create fixed-size array on the stack, but it shows stack overflow. When I change it to be on the heap (Rust by Example says to allocate in the heap we must us...
Mandrel asked 31/1, 2015 at 7:24
2
Solved
So I have a program in C structured in 3 files: main.c, alloc.h and alloc.c. In the main.c function, I have the declaration of a pointer to another pointer to which I intend to alloc an n * m array...
Trigger asked 28/11, 2016 at 21:49
1
Solved
This question is meant to be used as a canonical duplicate for this FAQ:
I am allocating data dynamically inside a function and everything works well, but only inside the function where the alloca...
Zoroastrianism asked 14/9, 2016 at 9:20
© 2022 - 2024 — McMap. All rights reserved.