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 4180
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. 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.
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) ?
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? 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. 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.
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.
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.
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.
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 ? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
|
by: Alex Vinokur |
last post by:
---------
#include <vector>
using namespace std;
struct Foo
{
Foo (int) {}
};
int main ()
{
vector<Foo> v1;
|
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...
|
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
|
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
| |
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 )
|
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;
...
}
|
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).
|
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(); //
}
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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();...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |