This question already has an answer here: How can I force the STL memory cache to clear? 2 answers I am using unordered_map using g++ 4.9.2 on Solaris 10, but surprisingly I found that clear() does not release heap. Here's the sample code: #include <
So i have a program in c structured in 3 files : main,alloc.h and alloc.c : In main i have the decclaration of a pointer to another pointer to which i intend to alloc a n*m array : #include <stdio.h> #include <stdlib.h> #include "alloc.h&
I'm aware you can use MemoryLayout<T>.size to get the size of a type T. For example: MemoryLayout<Int32>.size // 4 However, for class instances (objects), MemoryLayout<T>.size returns the size of the reference to the object (8 bytes on 6
I'm running a python script in pyspark and got the following error: NameError: name 'spark' is not defined I looked it up and found that the reason is that spark.dynamicAllocation.enabled is not allowed yet. According to Spark's documentation (https:
Preface: I've found nothing around about this issue. The only thing I've found is people dynamically allocating an array without providing any information about the size of said array, like this int* p = new int[]; My issue is different: float arr[]{
In C++ we have structures which have a constructor and the destructor. It makes life much easier especially when it going to have the pointers, therefore dynamically allocated memory in the structure. You can even use std::shared_pointer library to d
What is the difference between declaring an array "dynamically", [ie. using realloc() or malloc(), etc... ] vs declaring an array within main() with Global scope?, eg. int main() { int array[10]; return 0; } I am learning, and at the moment it f
To demonstrate, here is an example code recreating the instance of passing a dynamically allocated array to a function. #include <stdio.h> #include <stdlib.h> void fx1(int* arr) {/* code here */ } int main() { int *arr = (int *) malloc(sizeof(
When I dynamically allocate a structure, and then try to free it, it seems to reallocate it. typedef struct OBJ_T { int param1, param2; } OBJ; OJB* Construct(int par1, int par2) { OBJ* x = malloc(sizeof(OBJ)); x->param1 = par1; x->param2 = par2; ret
I'm trying to document some code to improve my knowledge of pointers and general ANSI C ability. ... int static_store = 30; const char * pcg = "String Literal"; int main() { int auto_store = 40; char auto_string[] = "Auto char Array";
I am trying to call malloc again after initializing another dynamically allocated array, but my program fails to run (though it can pass the compilation). Part of my code is as follows. table = (Node **)malloc(m * sizeof(Node*)); for(i=0; i<=m; i++)
I have declared a array of int in c++ with some size. say, int a[6] at runtime if my array size exceeds 6, then i need to increase it. i am not going to use pointer, vector and the size will not be given by the user.You can not change the size of you
I have an char array of fixed size in C application. I am passing that array to some function and from there I am passing it to multiple functions. So that the array gets filled in some of the functions based on some condition. Since I am sending a f
I am working on implementing a vector class but cannot figure out how to write a function to copy one vector into another. template <class T> class Vec { public: //TYPEDEFS typedef T* iterator; typedef const T* const_iterator; typedef unsigned int s
This question already has an answer here: Why should C++ programmers minimize use of 'new'? 17 answers Understanding the meaning of the term and the concept - RAII (Resource Acquisition is Initialization) 11 answers Like the following code : int size
I added a "search" function for my linked list menu and I don't know what is wrong in my code. When I enter a search key which is a name that is not in the list, instead of printing the "Search Key: %s Not Found!", the program will jus
I'm studying c++ and I'm reading about pointers. I'm curious about the following scenarios: Scenario 1: If I'm not mistaken, if the user types -1, there will be a memory leak: #include <iostream> using namespace std; int main(){ int *p = new int; co
Please the read the question instead of assuming this is a duplicate. In the codebase I am working on I have a list of Foo objects: private List<Foo> fooList; Could someone please explain to me the difference(s) between this line of code: Foo foos[]
Having a lot of trouble with this after sifting through many posts on here. Everything compiles but I get a crash right here during this function which should be dynamically allocating the addresses of one array into this array of pointers. I see one
void fun() { A *a = new A; //Here A is a class } //a should be deleted in fun()'s scope int main() { fun(); return 0; } The object created exists on the free store and cannot be used by the main() function. The why should the objects be created on th
I have a 2D array that I'm dynamically allocating at runtime, like so accData = calloc(nbox, sizeof(double *)); for(bb = 0; bb < nbox; bb++) accData[bb] = calloc(usedTime * usedChan, sizeof(double *)); and I want to only pass the second dimension to
I'm trying to build a program in C++ that works a lot with matrices and functions of matrices. My code compiles normally, but when I try to execute it I get the message: Segmentation fault (core dumped) My code has a lot of function that look like th
I have been trying to create a dynamically allocated array of struct type label and have been failing miserably. In my .h file, I have: typedef struct _label { char name[256]; char type[256]; int address; } label; and in my .c file, I have this at th
Hello so I am confused with my istream& operator>>. I have to overload this operator to take input for a class that is using dynamic memory allocation for a C string. My Employee.h file is #include <iostream> using namespace std; const dou
I want to do this but it doesn't work. Is it possible to do it or do I have to declare A as double pointer float**? Note that I need an universal function for various array dimensions so I can't change the function arguments. void func(float** arr, i
I'm having problems trying to use an array of structs which doesn't have an initial size. How do I do this? This is my struct: struct carbon { double temp; double mass; rowvec::fixed<3> position; rowvec::fixed<3> velocity; rowvec::fixed<3&g
As I make the transition from C# to C++ I get a lot of recommendations to use value semantics where possible. It's pretty much guaranteed that if I post a question with a pointer anywhere someone will come along and suggest that it should be a value
I need to return a char** but when I try to do this, the compiler tells me that I want to return the address of a local variable. How can I do that? I know that I should allocate space for this variable but how? Here is my code, but the second printf
Why do Objective-c objects have to be dynamically allocated? Why do I have to make it a pointer to an object, unlike in C++ I can create them on stack? Thanks.the primary reason: not knowing how much stack size to reserve. existing conventions and us
I saw this example when I was trying to figure out how to pass pointers to dynamically allocated 2d arrays to functions: void zeroit(int **array, int nrows, int ncolumns) { int i, j; for(i = 0; i < nrows; i++) { for(j = 0; j < ncolumns; j++) array[i