473,473 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SSE and Vector

Tao
hi.. Group,

I want to use __m128i with vector, but it seems does not work. The following
code generated a runtime error indicating that there is a memory corruption.
std::vector<__m128ilist;

__m128i x = _mm_set_epi32(0, 0, 0, 2);

list.push_back(x);

Can somebody tell me why this happen?

thanks.
Feb 9 '07 #1
1 2277
Tao wrote:
hi.. Group,

I want to use __m128i with vector, but it seems does not work. The following
code generated a runtime error indicating that there is a memory corruption.
std::vector<__m128ilist;

__m128i x = _mm_set_epi32(0, 0, 0, 2);

list.push_back(x);

Can somebody tell me why this happen?
__m128i requires 16-byte alignment, which vector doesn't guarantee to
provide (well, it should do, but __m128i has especially strict alignment
requirements - ones that aren't met by malloc). One way of working
around this would be to specify a special vector allocator which did
align the memory correctly. e.g. (VC2005 specific due to __alignof())

#include <vector>
#include <memory>
#include <malloc.h>
#include <emmintrin.h>

template <class T>
class aligned_allocator: public std::allocator<T>
{
public:
template <class U>
struct rebind
{
typedef aligned_allocator<Uother;
};

aligned_allocator(){}

template <class U>
aligned_allocator(aligned_allocator<Uconst& other){}

template <class U>
aligned_allocator& operator=(aligned_allocator<Uconst& other){
return *this;
}

T* allocate(std::size_t N, const void* hint)
{
return allocate(N);
}

T* allocate(size_type N)
{
return static_cast<T*>(_aligned_malloc(N * sizeof(T), __alignof(T)));
}

void deallocate(T* p, std::size_t N)
{
_aligned_free(p);
}
};

Then:
std::vector<__m128i, aligned_allocator<__m128i list;

Tom
Feb 9 '07 #2

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

Similar topics

9
by: {AGUT2}=IWIK= | last post by:
Hello all, It's my fisrt post here and I am feeling a little stupid here, so go easy.. :) (Oh, and I've spent _hours_ searching...) I am desperately trying to read in an ASCII...
9
by: luigi | last post by:
Hi, I am trying to speed up the perfomance of stl vector by allocating/deallocating blocks of memory manually. one version of the code crashes when I try to free the memory. The other version...
7
by: Forecast | last post by:
I run the following code in UNIX compiled by g++ 3.3.2 successfully. : // proj2.cc: returns a dynamic vector and prints out at main~~ : // : #include <iostream> : #include <vector> : : using...
34
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and...
10
by: Bob | last post by:
Here's what I have: void miniVector<T>::insertOrder(miniVector<T>& v,const T& item) { int i, j; T target; vSize += 1; T newVector; newVector=new T;
8
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
16
by: Martin Jørgensen | last post by:
Hi, I get this using g++: main.cpp:9: error: new types may not be defined in a return type main.cpp:9: note: (perhaps a semicolon is missing after the definition of 'vector') main.cpp:9:...
23
by: Sanjay Kumar | last post by:
Folks, I am getting back into C++ after a long time and I have this simple question: How do pyou ass a STL container like say a vector or a map (to and from a function) ? function: ...
6
by: zl2k | last post by:
hi, there I am using a big, sparse binary array (size of 256^3). The size may be changed in run time. I first thought about using the bitset but found its size is unchangeable. If I use the...
24
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public...
0
marktang
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.