473,563 Members | 2,762 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 #1
35 4152
im*****@hotmail .co.uk wrote:
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 ?
The below code works perfectly. Try posting the code that actually
produced the error.

#include <vector>

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

--
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 29 '06 #2

Daniel T. wrote:
The below code works perfectly. Try posting the code that actually
produced the error.
Indeed. How can I do that the whole thing is too large to post, but
why is it relevant. As I said I can post more but why ?

DEBUG_LOG("fn1" );
rv.resize(n); // error happens here
DEBUG_LOG("fn2" );

I know the error happens at rv.resize(n) because I don't get the output
from the second DEBUG_LOG.

Sep 29 '06 #3
On 29 Sep 2006 11:36:55 -0700, im*****@hotmail .co.uk wrote:
>Daniel T. wrote:
>The below code works perfectly. Try posting the code that actually
produced the error.

Indeed. How can I do that the whole thing is too large to post, but
why is it relevant. As I said I can post more but why ?

DEBUG_LOG("fn1 ");
rv.resize(n) ; // error happens here
DEBUG_LOG("fn2 ");

I know the error happens at rv.resize(n) because I don't get the output
from the second DEBUG_LOG.
A bus error usually stems from misaligned objects, not from the code
you posted. Do you use a custom memory allocator?
Sep 29 '06 #4

Roland Pibinger wrote:
A bus error usually stems from misaligned objects, not from the code
you posted. Do you use a custom memory allocator?
Do you mean like malloc, alloc etc and C++ new ?
No I am not using any of those or third party. I am only using reserve
and resize. Actually I am not using reserve on this particular
variable. I just tried it and it also failed.

DEBUG_LOG("fn0" );
rv.reserve(n); // error happens here now
DEBUG_LOG("fn1" );
rv.resize(n); DEBUG_LOG("fn2" );

Sep 29 '06 #5

<im*****@hotmai l.co.ukwrote in message
news:11******** *************@e 3g2000cwe.googl egroups.com...
>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 ?
Probably a bus error. A buss error occurs when you make a mistake kissing
someone. :-)

Seriously, the problem may stem from earlier, apparently unrelated code.
Using uninitialized variables or using objects which have been deleted or
writing past the bounds of an array are examples of problems which can often
cause errors to occur later in the code. The code above, by itself, looks
fine.

-Howard

Sep 29 '06 #6

Howard wrote:
Probably a bus error. A buss error occurs when you make a mistake kissing
someone. :-)
lol, it is a good word.
http://en.wikipedia.org/wiki/Buss
Seriously, the problem may stem from earlier, apparently unrelated code.
Using uninitialized variables or using objects which have been deleted or
writing past the bounds of an array are examples of problems which can often
cause errors to occur later in the code. The code above, by itself, looks
fine.

-Howard
So as I'm mostly using std vectors, one of these is likely to be the
culprit.
Thanks

Sep 29 '06 #7
im*****@hotmail .co.uk wrote:
Daniel T. wrote:
>The below code works perfectly. Try posting the code that actually
produced the error.

Indeed. How can I do that the whole thing is too large to post, but
why is it relevant. As I said I can post more but why ?
Because if you don't post the code that is actually causing the problem,
then no one can help you. BTW, don't post the whole thing. Start pairing
it down until you have the smallest example possible that still exhibits
the error. Nine times out of ten just trying to do that will help you
find the problem on your own.
DEBUG_LOG("fn1" );
rv.resize(n); // error happens here
DEBUG_LOG("fn2" );

I know the error happens at rv.resize(n) because I don't get the output
from the second DEBUG_LOG.
resize is not broken. Some code that you wrote is causing the problem.
What type is 'n'?

--
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 29 '06 #8

Daniel T. wrote:
resize is not broken. Some code that you wrote is causing the problem.
Yes, maybe I need to learn to use some kind of debugger to traceback
the problem.
What type is 'n'?
it is passed in as an int as in
void fn(.. , int n, ..)

I changed this to "const int &n" instead (this code is older code that
I started when I knew less) , but no that did not solve the problem.

Sep 29 '06 #9
im*****@hotmail .co.uk wrote:
Daniel T. wrote:
>resize is not broken. Some code that you wrote is causing the problem.

Yes, maybe I need to learn to use some kind of debugger to traceback
the problem.
>What type is 'n'?

it is passed in as an int as in
void fn(.. , int n, ..)

I changed this to "const int &n" instead (this code is older code that
I started when I knew less) , but no that did not solve the problem.

Are you checking that 'n' is not zero, and not negative?
How large might 'n' be?

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.
Sep 29 '06 #10

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

Similar topics

4
3393
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
3005
by: Alex Vinokur | last post by:
--------- #include <vector> using namespace std; struct Foo { Foo (int) {} }; int main () { vector<Foo> v1;
2
75779
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...
8
4879
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
3430
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...
2
2647
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...
18
2551
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
11891
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
1977
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
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
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. ...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
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...
0
6250
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...
1
5484
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...
0
5213
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.