Questions tagged [dynamic-allocation]

Use for questions related to *dynamic allocation of memory*, such as `malloc()` in C, `new` in C++, etc. . Please notice that the tag is not language specific.

From Wikipedia: "C dynamic memory allocation refers to performing manual memory management for dynamic memory allocation in the C programming language via a group of functions in the C standard library, namely malloc, realloc, calloc and free."

Please notice that the tag is not language specific.

506 questions
-1
votes
1 answer

How do I count words and lines that were input as a cstring array

This program should read a paragraph from a text file provided by the user and then store each line in a ragged char array and count the total number of words and lines of the paragraph then display the result. I can't figure out why does the number…
-1
votes
1 answer

dynamically allocated 2D array Runtime error

I was trying to solve this problem but this message appeared after finishing the first test case loop, and when i uploaded it to codeforces it gets a Run time error verdict! Given 2D Array of integers of size N*N. Print the sum of the perfect square…
-1
votes
2 answers

Functions for dynamically allocating an array in C -- Any difference between the two?

Suppose you have a function in C that accepts the dimensions for a 2d array (for simplicity's sake, say for a square nxn array), dynamically allocates the array, then returns it. I'm aware allocating memory here might be considered somewhat bad…
d0rz
  • 1
  • 1
-1
votes
1 answer

Multi-threaded Coin-toss Experiment

Main point up front: What do I need to do change to display the correct values for heads/tails in my records? Edit 1: The arrays of integers inside the Record appear to fill with random values once there is more than 1 thread. I've been trying to…
NonCreature0714
  • 5,744
  • 10
  • 30
  • 52
-1
votes
2 answers

How to free some dynamically allocated nested array of structure in C?

Here are some nested structures: struct bat { int match,run,fifty,best; double average,strike_rate; }; struct ball { char *best; int match,wicket,fiveW; double economy,average; }; struct Player { char *name; char…
Tavij
  • 98
  • 7
-1
votes
2 answers

No matching constructor when I overload operator for dynamic string class

I get a problem with my String class. Constructor and copy constructor: private: char * buf; public: String( const char * s = "") { buf = strdup(s); } String( String &s) : buf(strdup(s.buf)) { } The…
Ruidongd
  • 41
  • 5
-1
votes
3 answers

Overload delete operator in c++

I was overloading a delete operator in C++, I used free() for this: class A { private: int x; int y; public: void operator delete(void* ptr) { free(ptr); } void operator delete[](void* ptr) { free(ptr); …
-1
votes
2 answers

Unable to resolve this error of "Access violation"

I am trying to solve the PRIME1 problem of SPOJ using Sieve of Eratosthenes. The code works fine for lower integers but shows the following error for long ints - "Unhandled exception at 0x770d15ee in spoj1.exe: 0xC0000005: Access violation writing…
-1
votes
2 answers

Malloc returning Void in C

Guys I'm programing in C, trying to do a dynamic allocation of a type char like this : char **word1 = malloc(sizeof(char *)* 1); char **word2 = malloc(sizeof(char *) * 1); But it is resulting an erro like that: invalid conversion from 'void*' to…
-1
votes
1 answer

Dynamically allocating array in a function in c++

In a part from a project I'm working on I'm implementing an AVL tree. One of the functions I need to implements receives and array of Key (template class for the tree's keys) and an int pointer (to which I need to insert the size of the AVL tree).…
-1
votes
1 answer

Hi, I very confused on why I am getting a compilation error mainly: "Library.cc:(.text+0x27): undefined reference to `PatronArray::PatronArray()'"

this my Library.h file, before the Library used to do All the dirty work: in term of manipulating the arrays and stuff, but now I am trying to make the Library the middle man that just invoke the call that has to do with any array manipulations. My…
mvitagames
  • 413
  • 3
  • 6
  • 16
-1
votes
2 answers

difference between dynamic allocation static allocation

MY question is In any programming language is dynamic memory allocation faster than static memory allocation? int main(int, char**) { int *pa = new int; // faster than int a; // ? return 0; }
karan
  • 398
  • 4
  • 5
-1
votes
3 answers

C-string memory allocation, table of C-strings

I want to make dynamically allocated c-string table, but I think i don't understand the topic very well, could You explain it to me or correct my code? #include int main() { int i; char** t; …
-1
votes
1 answer

dynamic allocation and destruction of an array in a class

I'm trying to implement a game of life program in C++. I wish to resort only to basic tools, ie no vector whatsoever, in order to understand what is going on behind the scene. I have a world class, like this: class World { private: int…
Napseis
  • 833
  • 2
  • 10
  • 24
-1
votes
1 answer

Linked List Deck of Cards - Access violation reading location

So, I'm trying to create a deck of cards using Linked List for a class, but I am having an extremely hard time trying to figure out why I have the error: Access violation reading location 0x00000020. I'm still new to coding and dynamic allocation,…
Shannon
  • 119
  • 1
  • 1
  • 10