dynamic-memory-allocation Questions
3
Solved
I have a class that stores the latest value of some incoming realtime data (around 150 million events/second).
Suppose it looks like this:
class DataState
{
Event latest_event;
public:
//pus...
Cessionary asked 28/8, 2016 at 19:59
4
Solved
I know how to create a array of dynamic objects.
For example, the class name is Stock.
Stock *stockArray[4];
for(int i = 0 ; i < 4;i++)
{
stockArray[i] = new Stock();
}
How do you change t...
Parotic asked 30/11, 2013 at 18:11
3
Solved
I don't understand one thing. For example, I declare class A and class B which is a child of A:
class A {
public:
int a;
}
class B : public A {
public:
int b;
}
Obviously, if I create insta...
Wanids asked 6/6, 2016 at 0:47
3
Solved
I was curious about what exactly a pointer holds, after malloc() was used to allocate memory space? The manpage tells me that calloc() initializes the allocated memory space with zero.
The mallo...
Irreparable asked 12/5, 2016 at 10:50
2
Solved
This is a bit complicated; I'd welcome any comments on how to improve the clarity of the question.
Ok, say I have an array:
real, allocatable :: A(:,:,:)
and I want to allocate it before I use ...
Wawro asked 19/12, 2011 at 4:31
3
Solved
So we have a constructor that can throw an exception depending on the arguments passed to it, but we do not know how to delete the object if this occurs. Important part of the code:
try
{
GameBas...
Tripos asked 30/3, 2016 at 7:20
3
Solved
Does ::operator new(size_t) call malloc() internally, or does it use system calls / OS-specific library calls directly? What does the C++ standard say?
In this answer it says that:
malloc() is ...
Assyrian asked 15/1, 2016 at 14:37
4
Solved
I have been taught in lectures, that calling free() on a pointer twice is really, really bad. I know that it is good practice, to set a pointer to NULL, right after having freed it.
However, I st...
Fiji asked 15/12, 2015 at 9:0
5
Solved
When processing some stream of data, e.g., requests from a network, it is quite common that some temporary memory is used. For example, a URL may be split into multiple strings, each one possibly a...
Respectively asked 2/12, 2015 at 8:43
5
So, I think I've searched the web quite thoroughly about this and found nothing really useful (just confusing at most...).
I'd like to know how I can (if possible) use Qt with non-dynamic memory. ...
Emlen asked 13/12, 2013 at 14:38
3
Solved
There are a few options for acquiring an aligned block of memory but they're very similar and the issue mostly boils down to what language standard and platforms you're targeting.
C11
void * alig...
Grayce asked 16/9, 2015 at 15:30
3
Solved
I want to only allow use of std::function in my code base if it does not do any allocations.
To this end I can write something like the function below and only use it to create my function instanc...
Baxy asked 27/8, 2015 at 16:4
6
Solved
If I allocate memory dynamically in my program using malloc() but I don't free the memory during program runtime, will the dynamically allocated memory be freed after program terminates?
Or if it ...
Comatose asked 22/8, 2015 at 8:13
2
Solved
I would like to use C++11's std::aligned_alloc, but unfortunately it isn't available with Microsoft Visual Studio 2013.
I'm considering, intsead, implementing aligned_alloc on my own. How should ...
Arezzo asked 21/8, 2015 at 5:49
4
Solved
Given availability of make_unique and make_shared, as well as automatic deletion by unique_ptr and shared_ptr destructors, what are the situations (apart from supporting legacy code) for using new ...
Deafening asked 10/6, 2015 at 17:12
2
Solved
Say I have:
vector<string>* foo = new vector<string>();
I add a ton of stuff to it, use it, and then I just call:
delete foo;
Did I need to call foo.clear(); first? Or will the de...
Preuss asked 11/6, 2015 at 15:10
3
Solved
I am learning about dynamic memory in C++. What I learned as a standard way of allocating & deallocating dynamically for any data type is, for example,
//For double,
double* pvalue1 = nullptr;...
Epiphenomenalism asked 27/5, 2015 at 12:32
1
While declaring an array in java we have to dynamically allocate the memory using new keyword.
class array
{
public static void main(String ars[]) {
int A[] = new int[10];
System.out.println(...
Evangelistic asked 16/5, 2015 at 5:27
2
When pre-allocating using std::string::reserve do I have to add one for the terminating 0 explicitly in order to avoid re-allocation and subsequent copying?
For example, knowing that the string "H...
Haubergeon asked 7/5, 2015 at 20:43
2
Solved
I know that calloc allocates memory and writes zeroes to each cell, so my question is:
is there a difference between using calloc or using malloc and running over the cells writing NULL to them? Ar...
Xochitlxp asked 22/4, 2015 at 14:24
4
Solved
Is there a difference between setting a pointer to NULL before and after allocating it?
For example, is there any difference between
char* c = NULL;
and
char* c = malloc(sizeof(char));
c = NU...
Logicize asked 22/3, 2015 at 4:6
4
The compiler throws runtime segfault upon following code :
#include <iostream>
#include <string>
using namespace std;
struct Node{
int data;
void *next;
string nodeType;
};
Node*...
Romberg asked 17/3, 2015 at 9:50
3
I'm reading Effective C++ 55 by Scott Meyers and have a question from item 49:
When operator new is unable to fulfill a memory request, it calls the
new-handler function repeatedly until it can fi...
Premises asked 16/2, 2015 at 12:33
5
Solved
I am doing an exercise for fun from KandR C programming book. The program is for finding the longest line from a set of lines entered by the user and then prints it.
Here is what I have written (p...
Crape asked 4/7, 2014 at 19:1
3
Solved
#include<stdio.h>
#include<string.h>
char *y;
y=(char *)malloc(40); // gives an error here
int main()
{
strcpy(y,"hello world");
}
error: conflicting types for 'y'
error: previous ...
Judd asked 19/7, 2011 at 5:52
© 2022 - 2024 — McMap. All rights reserved.