C++ :: Vector Causing Memory Errors On Destruction?

Sep 10, 2013

std vector seems to cause errors when destructing here some simplified code:

#include <stdlib.h>
#include <stdio.h>
#include <vector>
class Foo{

[Code]....

View 5 Replies


ADVERTISEMENT

C++ :: Extract Chunks Of Numbers From A Stream - Lambda Functions Causing Errors

Jul 1, 2014

I am trying to write a function that extracts chunks of numbers from a stream (ie if i had "ui33ui24ui23hjdwejf" it would extract the chunk 33), and its finished, but it wont compile. errors here: [URL] ...... its only one line in an include file, but im stumped. anyways, this is the most updated version of the code: [URL] .....

View 1 Replies View Related

C++ :: Dynamic Memory Errors

Feb 15, 2013

I am new to C++ language and I am still learning.I'm doing basic stuff to better understand dynamic memory. I was wondering why I keep getting memory issues.*/

#define SIZE 15
class word {
char* str;
public:

[code]....

View 1 Replies View Related

C++ :: Vector Subscript Out Of Range - No Errors

Feb 13, 2013

When i build this program i get no errors, however a message appears saying vector subscript out of range. What does this mean and what can i do to mkae my program work

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <cstring>
#include <time.h>
#include <vector>
using namespace std;

[Code] .....

View 19 Replies View Related

C++ ::  Improper Destruction Of Objects

Feb 2, 2014

I have two simple classes: Author and Book. Class Author contains class Book as a member. Additionally i have a list of Book objects within each Author class.

//Book.h
#include <iostream>
#include <string>
#include <cstring>
class Book{

[Code] ....

//output WITHOUGHT debugging
variable bname before exiting my Book constructor:A Frogs thug life
Book's name:A Frogs thug life
Book's realese date:1993

Author's name:Alex
Author's birth date:1892

variable bname before exiting my Book constructor:Life on Jupiter
destructor of Book called
Book's name:▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌♀
Book's realese date:1991
Press any key to continue . . .

Basically these are my problems:
- Why is the Book's instance's destructor called right after my program exits Book's construcor
- Does Book's name(during the output of my Print() method) print these wierd symbols due to the fact that this instance of Book got destroyed?
-if this instance of Book actually got destroyed before the Print() method,why the hell is it able to print the Book's release date?

View 2 Replies View Related

C++ :: Singleton Destruction Order

May 28, 2012

I've been upkeeping a mess of a code recently, that uses "pseudo" singletons. Basically, the current code has "Initialize_All" static functions that initializes all the singletons in a given order. At the end of the program, we call "Destroy_All", and destroy everything in the reverse order.

The code is actually heavilly dll'ed, and Initilize_All and Destory_All are referenced counted. We ask that any client who uses our code call Initialize_All first and then Destroy_All when they are finished. The first Initilize_All will initialize everything, and the last Destory_All will delete everything.

This is showing its limits.

I'd like to move us to a fully singleton design. The singleton pattern means we don't have to use an Initilize_All, and each singleton can manage construction dependencies by itself (we are mono-threaded).

Each singleton is "clean", so it is cleans itself up at dll destruction.

The big question is this one:

If there is a singleton dependency during destruction, eg: ~A requires an instance of singleton B (which is in another DLL), are we guaranteed proper behavior?

Or, is there an "Static de-initialization order fiasco"?

If yes, are there any design that can combat this fiasco, short of having each singleton register itself in a manager, that will destroy them in reverse order?

View 6 Replies View Related

C++ :: Vector Memory Allocation?

Jan 21, 2014

I am trying to allocate a memory to vector but while running the program,my window appear and PC get halt state then i have to force fully shutdown my PC I found that due to the vector i am getting this problem.

#define SCOPEPLOT_MAXNUM_SAMPLES (1000000)
QHash<int, std::vector<double>*> m_sampleHash;
m_sampleHash.insert(1, new std::vector<double>(SCOPEPLOT_MAXNUM_SAMPLES));
std::vector<double>* vec_p = m_sampleHash.value(1);
for(int k = 0;k < numSamples;k++)
{
count++;
vec_p->at(k) = data_p[k];
}

View 5 Replies View Related

C++ :: Vector Memory Allocation

Apr 15, 2014

vector<Type> vect; //allocates vect on stack and each of the Type (using std::allocator) also will be on the stack

vector<Type> *vect = new vector<Type>; //allocates vect on heap and each of the Type will be allocated on stack

vector<Type*> vect; //vect will be on stack and Type* will be on heap.

What I would like to know is, are all of the above statements true?

View 3 Replies View Related

C++ :: Memory Size Of Vector Elements

Apr 9, 2014

I had a question about memory allocation/how iterators work for a std::vector<foo> of a user defined class 'foo'. Say foo contains variables of variable size, so that each member of the std::vector<foo> does not require the same amount of memory space.

Does c++ allocate the same amount of memory for each element, equal to the amount of memory required for the largest element? Or does it use some sort of array of pointers pointing to the location of each element in the vector to make the iterator work? Or does it use some other method? I am wondering because I wrote a code which reads data from a binary files and stores most of it in std::vectors.

The code seems to be using significantly more memory than the sum of the size of all the binary files, and I am using vectors made up of the datatype within the binary files (float). So I was wondering if internally the code was allocating space for each vector element which is the size of the largest element as a way to handle indexing/iterators. I ran my code through a memory leak checker and it found no errors.

View 16 Replies View Related

C++ :: Memory Allocated To Vector At Certain Point In Time?

May 7, 2013

I have a pretty big std::vector<matrix>, where matrix is a custom class defined by me. I would like to know how much memory has been allocated to that vector at a certain point in time. Is there any way of doing this in c++?

Or is my only shot, taking a look at the task monitor of windows/unix/whatever at execution time to estimate this?

View 2 Replies View Related

C/C++ :: Passing Vector As Reference Memory Leak?

Nov 30, 2014

I asked a few questions a few weeks ago about vectors and the fact that their data is stored on the heap. When a function closes, anything in its scope is destroyed, if it's passed by reference it won't be destroyed since it's outside the scope.

I have a program where I create a vector in one function, then pass it by reference to another. When I test for memory leaks, I get told I have 1 memory leak in in my start() function, and one memory leak in my save() function.

It's just a simple program that creates a vector, populates it with some numbers, then saves the numbers in a file. If I'm passing my vector by reference to another function, do I need to manually do something to avoid memory leaks? I'll post the code below.

#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>

[Code].....

View 2 Replies View Related

C++ :: Calling Dynamically Loaded Function From DLL Destruction Error?

Apr 18, 2013

I have two projects (Projects A and B). Project A is a dll project, defining a function called "regex".

Project B dynamically loads this DLL, and calls Project A's "regex" function via LoadLibrary/GetProcAddress.

Regex takes a pointer to an std::vector (std::vector<std::cmatch>).

When debugging ProjectB, I can see that, within the code from ProjectA (in the "regex" call), a loop that loops through the elements of the vector outputs all the elements in the vector to console as expected. But the loop in ProjectB ( which executes after ProjectA), which also loops through the vector, and, is supposed to output the elements of the vector, outputs empty strings, not, as I would expect, the same strings (which contain results), as in the loop in Project A.

How is this happening. Does this have anything to do with it being a DLL, and, maybe, somehow values/memory addresses (or something similar) of the vector/its elements being destructed across the Projects/Dlls?

Output and Code See Below:

Output Loop in A:

Un
Un

Output Loop in B: (empty) (i.e. none)

Project A DLL Header (interface.h):

#include "stdafx.h"
#include <vector>
#include <regex>
extern "C" {__declspec(dllexport) int __cdecl regex(std::string target,std::string rgx, std::vector<std::cmatch*>* matches);}

[Code].....

View 8 Replies View Related

C/C++ :: Write Function For Destruction Of Planetary System Solid

Dec 18, 2014

I have to write a function for the destruction of the planetary system "solid". With the destruction of the planetary system, the asteroids where the gap between this one and the object, is smaller that "gap" will also be destructed. (so, they have to be deleted) The asteroids for which the gap is greater are converted to free-floating planets so they have to be inserted into the tree of free-floating planets. The total cost of the transport of all the asteroids that are converted into free-floating planets in the tree of free-floating planets should be $O(n)$, where $n$ is the maximal between the elements of the tree of free-floating planets of the star system to which the object belongs and the elements of the tree of asteroids of the planetary system of which the object has identifier "solid". The field "gap" of the new tree should have the value $0$. The destructed planetary system should be deleted from the list of planetary systems of the star system to which it belonged. (The tree of free-floating planets is not a binary search tree)

I have done the following: [URL]

Is the way I deleted the nodes correct??

View 4 Replies View Related

C :: Sscanf Causing Segmentation Fault

May 30, 2014

I have a problem in my code and after hours of looking I really cannot find out what is the problem.I use scanf to to parse lines of a file, let me copy only the important part:

Code:

/*File read...everything is fine*/
int seq_1, seq_i2;
int len;
while(fgets(&line[strlen(line)], line_length, file)!= NULL) {
}

[code]....

if (num_sc ==4) //the wanted format, do something So I am allocating all variables, and giving to sscanf pointers, so I really don't get where the segmentation fault appears.I checked with the debugger, the first line of the file is read, but at the second it crashes at the line of sscanf! The two lines don't have the format I want in sscanf but therefore I check if this number is 4 and then do other stuff to the data...

View 9 Replies View Related

C++ :: Function Causing Infinite Recursion Crash

Oct 24, 2014

This function is apparently causing infinite recursion, but I have no clue what's causing it:

Code:
int pow( int base, int exp ) { int somevariable = pow(base,exp-1);
if (exp == 0) {
return 1;
}
else {
return base * pow(base,exp-1);
}
}

View 10 Replies View Related

C++ :: Vector Of Int Class - How To Delete Pointer X In Destructor To Free Memory

Feb 25, 2015

An attempt to create a class which is basically a mimic of vector<int> i don't seem to know how to delete pointer x in a destructor to free memory, also on pushback and pushfront methods, i can't free y when i implement delete[] y; y=NULL; i get some NULL out put when cout 'ing the object in main, why is that happening and how do i free memory y.

#include<iostream>
using namespace std;
class vectorOfint{
int* x;
int size;
public:
vectorOfint();

[Code] .....

View 6 Replies View Related

C++ :: Destructor And Inheritance Causing Program To Crash After Running?

Dec 13, 2013

I have a class which dynamically allocates memory for three data arrays, and as such in the destructor I told it to delete those data arrays.

However, when I've created a new class, and inherited the previous class - it will always crash AFTER running the program, unless I don't have the previous destructor present.

View 3 Replies View Related

C# :: Picture Cropping Code Causing Error In Main Program

Jan 24, 2014

Ok, this thing works as far as the getting the image and drawing the rectangle but for the life of me I cannot figure out why it is causing an in the program.cs.

public partial class Crop : Form {
public Crop(Image BaseImage) {
InitializeComponent();
if ((Bitmap)BaseImage != null) { pbOriginal.Image = BaseImage; }

[Code] ....

BaseImage is pulled in from the main form's picture box.

View 14 Replies View Related

C++ :: Using Vector Push Back Function To Output Contents Of Vector (similar To Array)

Feb 9, 2015

How to output vector contents using the push_back function. My program reads in values just fine, but it does not output anything and I've been stuck on why.

here is my code:

#include <iostream>
#include <array>
#include <vector>
using namespace std;
int duplicate( vector < int > &vector1, const int value, const int counter)

[Code].....

View 3 Replies View Related

C++ :: Open File And Read In Rows To String Vector And Return Vector

Jun 7, 2012

I have a cpp app that reads in a number of files and writes revised output. The app doesn't seem to be able to open a file with a ' in the file name, such as,

N,N'-dimethylethylenediamine.mol

This is the function that opens the file :

Code:
// opens mol file, reads in rows to string vector and returns vector
vector<string> get_mol_file(string& filePath) {
vector<string> mol_file;
string new_mol_line;
// create an input stream and open the mol file
ifstream read_mol_input;
read_mol_input.open( filePath.c_str() );

[Code] ....

The path to the file is passed as a cpp string and the c version is used to open the file. Do I need to handle this as a special case? It is possible that there could be " as well, parenthesis, etc.

View 9 Replies View Related

C++ :: Create Class Vector As Template And Define Operations On Vector?

May 13, 2013

I need to create a class vector as a template and define operations on vectors.

And this is what I made.

#include<iostream>
using namespace std;
template<class T>

[Code].....

View 2 Replies View Related

C++ :: Seg Fault Run Errors

Mar 25, 2014

identify the reason why I am getting a seg fault run error? I hate to bother but I've been trying for several days now to fix the same function.

class adjacencyList {
public:
explicit adjacencyList(int size);
void buildGraph(Edge inEdge);
void print();

[code].....

View 6 Replies View Related

C++ :: Recursive Function 2 - Create Vector Of Vector Of Integers

Mar 26, 2013

Lets say that I have a vector of vector of integers. <1,2,3,4> , <5,6,7,8>, <10,11,12,13>

How do I make a function that creates vector of vector of every different integers?

<1,5,10> , <1,5,11>, <1,5,12>, <1,5,13>
<1,6,10> , <1,6,11>, <1,6,12>, <1,6,13>
<1,7,10> , <1,7,11>, <1,7,12>, <1,7,13>
<1,8,10>, <1,8,11>, <1,8,12>, <1,8, 13>
<2,5,10>, <2,5,11>, <2,5,12>, <2,5,13>

and so on...

View 2 Replies View Related

C :: Redefinition Errors In When Compiling

Sep 8, 2013

have several linux header files included and when I compile my program I get the below errors..Am I NOT supposed to use some of these headers? Source is below as well.Looking through the headers mentioned in these errors, it's looking like stuff really is defined in multiple places...

Code:

codeblox@Lubuntu-pc:~/Programming/C/Network/MITM/src$ gcc -g -o mitm *.c
In file included from mitm.h:12:0,
from create_raw.c:1:
/usr/include/netpacket/packet.h:22:8: error: redefinition of ‘struct sockaddr_ll’
In file included from /usr/include/linux/netdevice.h:30:0,
from /usr/include/linux/if_arp.h:26,
from mitm.h:10,
from create_raw.c:1:
}

[code]....

View 5 Replies View Related

C++ :: Cstddef Declaration Errors

Feb 17, 2013

I've included <cstddef> into a project of mine in favour of <stddef.h>. When I tried to compile my project, I get 50+ errors stating that types such as "::size_t", "::div_t" and "::abort( )" have not been declared even though <cstddef> includes <stddef.h>.

I've tried searching both the global namespace and the standard namespace, but neither way works. At this moment in time, I don't have any compiler options enabled that may affect the way identifiers are defined, C++11 isn't enabled (which doesn't affect the <cstddef> header anyway), the project is a C++ project, and I've tried using the plain old <stddef.h> header, but the problems still persist.

I'm using GNU's C++ compiler ("__GNUG__" is defined).

View 3 Replies View Related

C++ :: Getting Data And Reporting Errors

Dec 31, 2014

At this stage I will obtain Dimensions A, B & C. But after this before I do the pythagoras equation using the data I want it checked over. I think I've done this here but I'm not sure. I want it to report the message "Invalid Data" if Dimension A is not the longest.

cout << "Enter Dimension A:-";
cin >> DimA;
cout << "Enter Dimension B:-";
cin >> DimB;
cout << "Enter Dimension C:-";
cin >> DimC;
if (DimA >= DimB, DimC)
cout << endl << "Invalid Data";

View 15 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved