- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
I am using pointer to dynamic allocate a 3D array like this:
double ***p;
p=new double** [x_dimension];
for (int i=0; i<x_dimension; i++)
{
phi=new double* [y_dimension];
for(int j=0; j<y_dimension; j++)
{
phi
}
}
How can I rewrite the code to make sure the allocated memory is 64 bytes alignment?
Thanks!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
At least in Linux, Intel compilers support their own allocators _mm_malloc. The syntax is:
phi= (double*) _mm_malloc(sizeof(double)*z_dimension, 64); // ... _mm_free(phi );
If you must use operator new, you can use the placement version, but you have to call _mm_free explicitly to release memory:
#include <new> phi= new ( (double*) _mm_malloc(sizeof(double)*z_dimension) ) double[z_dimension]; // ... _mm_free(phi );
// ...
The placement version of operator new is actually more useful for aligned class objects than for arrays. Note that you cannot delete the memory for that object in the usual way. You have to call the constructor followed by a call to _mm_free:
#include <new> class MyClassType { // ... }; MyClassType* c = new ( (MyClassType*) _mm_malloc(sizeof(MyClassType) ) MyClassType; // ... c->~MyClassType(); _mm_free(c);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No idea why Posts #5 and #6 are duplicates...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page