473,722 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

bus error, resize vector

I get a bus (or is it buss) error when I resize a vector

typedef std::vector<dou bledblvec;
n = 127;
dblvec rv;
rv.resize(n); // error happens here

Any clues ? I can post more info if required ?

Sep 29 '06
35 4185

Larry Smith wrote:
Are you checking that 'n' is not zero, and not negative?
How large might 'n' be?
OK its way past my original post
n=127;
>
If you're validating 'n' before using it, then I'd
look elswhere - something is probably trashing memory,
causing this failure as a side effect.
I looked at all the std::vectors, they all seem to be sized. This
could be tricky, what else tends to do this ? I don't have any
pointers as such except for some function pointer, but since this gets
used lots and I checked it, it is unlikely to be that.

Sep 30 '06 #11
im*****@hotmail .co.uk wrote:
Larry Smith wrote:
>Are you checking that 'n' is not zero, and not negative?
How large might 'n' be?

OK its way past my original post
n=127;
>>
If you're validating 'n' before using it, then I'd look elswhere -
something is probably trashing memory, causing this failure as a
side effect.

I looked at all the std::vectors, they all seem to be sized. This
could be tricky, what else tends to do this ? I don't have any
pointers as such except for some function pointer, but since this gets
used lots and I checked it, it is unlikely to be that.
Here's a simple thing to do that might find the problem. Replace all
vector array references with the 'at' function. Try this:

First do a find and replace in all files from "vector" (or "std::vecto r"
if you didn't use any using directives) to "Vec".
Change all references of #include <vectorto #include "Vec.h"
Make a Vec.h file with the following in it:

#include <vector>

// taken from TC++PL 3rd Ed.

template < typename T >
class Vec : public std::vector< T {
public:
Vec():vector<T> () { }
Vec( int s ) : vector<T>(s) { }
T& operator[](int i) { retur at(i); }
const T& operator[](int i ) const { return at(i); }
};

See if that causes the error to move somewhere closer to the actual
problem.

--
There are two things that simply cannot be doubted, logic and perception.
Doubt those, and you no longer*have anyone to discuss your doubts with,
nor any ability to discuss them.
Sep 30 '06 #12

Daniel T. wrote:
Here's a simple thing to do that might find the problem. Replace all
vector array references with the 'at' function. Try this:

First do a find and replace in all files from "vector" (or "std::vecto r"
if you didn't use any using directives) to "Vec".
Change all references of #include <vectorto #include "Vec.h"
Make a Vec.h file with the following in it:

#include <vector>

// taken from TC++PL 3rd Ed.

template < typename T >
class Vec : public std::vector< T {
public:
Vec():vector<T> () { }
Vec( int s ) : vector<T>(s) { }
T& operator[](int i) { retur at(i); }
const T& operator[](int i ) const { return at(i); }
};

See if that causes the error to move somewhere closer to the actual
problem.

--
There are two things that simply cannot be doubted, logic and perception.
Doubt those, and you no longer have anyone to discuss your doubts with,
nor any ability to discuss them.
I replaced my matvec.h with this

#include <vector>

template < typename T >
class Vec : public std::vector< T {
public:
Vec():vector<T> () { }
Vec( int s ) : std::vector<T>( s) { }
T& operator[](int i) { return at(i); }
const T& operator[](int i ) const { return at(i); }
};

typedef Vec<doublevecdb l;
typedef Vec<vecdblmatdb l;

The compiler went "nuts" threw too many messages to print here, but I
can post them. Is there anything obviously wrong with this template
definition (typo etc) ?

Sep 30 '06 #13
In article <11************ **********@c28g 2000cwb.googleg roups.com>,
<im*****@hotmai l.co.ukwrote:
>
Daniel T. wrote:
>Here's a simple thing to do that might find the problem. Replace all
vector array references with the 'at' function. Try this:

First do a find and replace in all files from "vector" (or "std::vecto r"
if you didn't use any using directives) to "Vec".
Change all references of #include <vectorto #include "Vec.h"
Make a Vec.h file with the following in it:

#include <vector>

// taken from TC++PL 3rd Ed.

template < typename T >
class Vec : public std::vector< T {
public:
Vec():vector<T> () { }
Vec( int s ) : vector<T>(s) { }
T& operator[](int i) { retur at(i); }
const T& operator[](int i ) const { return at(i); }
};

See if that causes the error to move somewhere closer to the actual
problem.

--
There are two things that simply cannot be doubted, logic and perception.
Doubt those, and you no longer have anyone to discuss your doubts with,
nor any ability to discuss them.

I replaced my matvec.h with this

#include <vector>

template < typename T >
class Vec : public std::vector< T {
public:
Vec():vector<T> () { }
Vec( int s ) : std::vector<T>( s) { }
T& operator[](int i) { return at(i); }
const T& operator[](int i ) const { return at(i); }
};

typedef Vec<doublevecdb l;
typedef Vec<vecdblmatdb l;

The compiler went "nuts" threw too many messages to print here, but I
can post them. Is there anything obviously wrong with this template
definition (typo etc) ?
If that's the exact code, see:

http://www.comeaucomputing.com/techtalk/#usestd
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Sep 30 '06 #14

im*****@hotmail .co.uk wrote:
The compiler went "nuts" threw too many messages to print here, but I
can post them. Is there anything obviously wrong with this template
definition (typo etc) ?
OK, different errors now, I will start a new post.

Sep 30 '06 #15
im*****@hotmail .co.uk wrote:
Daniel T. wrote:
Here's a simple thing to do that might find the problem. Replace all
vector array references with the 'at' function. Try this:

I replaced my matvec.h with this

#include <vector>

template < typename T >
class Vec : public std::vector< T {
public:
Vec():vector<T> () { }
Vec( int s ) : std::vector<T>( s) { }
T& operator[](int i) { return at(i); }
const T& operator[](int i ) const { return at(i); }
};

typedef Vec<doublevecdb l;
typedef Vec<vecdblmatdb l;

The compiler went "nuts" threw too many messages to print here, but I
can post them. Is there anything obviously wrong with this template
definition (typo etc) ?
Just post the first three errors to us and let's see what they say.

--
There are two things that simply cannot be doubted, logic and perception.
Doubt those, and you no longer*have anyone to discuss your doubts with,
nor any ability to discuss them.
Sep 30 '06 #16

Daniel T. wrote:
Just post the first three errors to us and let's see what they say.
Sorry, I removed this template declaration on advice from someone else,
they made a criticism. Perhaps if you could explain the context and
removed the typos it might help. Also the namespace helps too.

Sep 30 '06 #17
I changed it back to composition and now I get a different error
message at runtime. Doing a resize on a std::vector I get glibc
detected malloc memory corruption. The difference now is that I don't
use any arrays now, all std::vectors. Some of these are vectors of
structs.

Sep 30 '06 #18
In article <11************ **********@m7g2 000cwm.googlegr oups.com>,
im*****@hotmail .co.uk wrote:
I changed it back to composition and now I get a different error
message at runtime. Doing a resize on a std::vector I get glibc
detected malloc memory corruption.
That's telling you that at some earlier time, you wrote to memory you
didn't have access to.
The difference now is that I don't
use any arrays now, all std::vectors. Some of these are vectors of
structs.
Now change all the op[] calls with at(). If you use all vectors, you can
do that with a global replace of '[' with "at(" and then globally
replace ']' with ")".

That will likely find your error real quick.

--
There are two things that simply cannot be doubted, logic and perception.
Doubt those, and you no longer*have anyone to discuss your doubts with,
nor any ability to discuss them.
Sep 30 '06 #19
Now change all the op[] calls with at(). If you use all vectors, you can
do that with a global replace of '[' with "at(" and then globally
replace ']' with ")".
Do you mean change x[i] to x(i) or something else ?

Sep 30 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3404
by: Peter Mrosek | last post by:
Hello, I have the following declaration in an header file (abbreviated version): typedef struct { unsigned char rgbBlue; unsigned char rgbGreen; unsigned char rgbRed; unsigned char rgbReserved;
9
3013
by: Alex Vinokur | last post by:
--------- #include <vector> using namespace std; struct Foo { Foo (int) {} }; int main () { vector<Foo> v1;
2
75791
by: B_Love | last post by:
Hey! When trying to compile the code for a ordered vector class I get the following error: undefined reference to `WinMain@16' Anyone have any idea what I might be doing wrong? I've been through this code multiple times and have no idea what would cause an error like this, I've never seen one like it before. Any help would be greatly appreciated. The class is supposed to be able to create a sorted list of vectors of type Object. If an...
8
4909
by: Jason Heyes | last post by:
Does the STL have a function like this one? template <typename T> void remove(std::vector<T> &v, std::vector<T>::size_type index) { std::swap(v, v.back()); v.resize(index); } Unlike std::vector::erase, it calls T::operator= only three times no matter
2
3446
by: mj | last post by:
Hi, I recently have found it necessary to move from fortran to c++ for scientific programming... I'm working on a program that needs to resize a 2d vector of vectors within a function... This variable "tri" is an input arg to my function using the syntax: function(vector<vector<int> >& tri) The problem occurs when the tri 'matrix' is resized to triple or
2
2664
by: mrbrightsidestolemymoney | last post by:
Hi, I'm having a problem resizing a (very big) nested vector. It's not the most streamlined piece of code ever but I need this array to avoid having to recalculate the same quantity millions of times! The (relevant) snippets of code are below : since it's relevant though L=28,T=96 (so TasteProps weighs in at a hefty 8*96*28*28*28*96=1,618,477,056 doubles )
18
2566
by: imutate | last post by:
I have an integer variable and I am testing it as follows #define NULL_VAL -1 ... if (x.id != NULL_VAL) { std::cout << x.id << std::endl; ... }
17
11917
by: toton | last post by:
Hi, I am using a vector to reserve certain amount of memory, and reuse it for new set of data, to avoid reallocation of memory. so the call is something like vector<my_datav;///the temporary storage. v.reserve(300); ///at max I have 300 data. now, my_data doesn't have a default ctor (as it doesn't have a default state).
2
1984
by: nikiplos | last post by:
Hi, all... I have a problem when trying to reallocate a vector for a second time inside a loop. The order is somelike: for (n=k; n<L; n++) { vector.resize(n, (long) 0); ... vector.clear(); // }
0
9384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.