Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

Corrupted heap on 64 bit platforms using Ipp32f** and ippsMalloc_32f to allocate memory

Peter_N_1
Beginner
498 Views

I have a very simple problem. A program like folows works on 32 bit platforms Windows and linux. On 64 bi platforms the program results in a corrupted heap. Example for the program:

************************************************

Ipp32f** x = (Ipp32f**)ippsMalloc_32f(19);

for( int i = 0; i < 19; i++ ) {
  x = (Ipp32f*)ippsMalloc_32f(100);
  for( int k = 0; k < 100; k++ ) {
    x = 0.0;
  }
}

for( int j = 0; j < 19; j++ ) {
  if( x != NULL ) {
    ippsFree(x);
    x = NULL;
  }
}
ippsFree(x);
x = NULL;

************************************************

In the reference manual I found something like
...
Ipp32f* ippsMalloc_32f(int len);
...

Example
The following example shows how to use the function ippsMalloc_8u:
void func_malloc(void) {
Ipp8u* pBuf = ippsMalloc_8u(8*sizeof(Ipp8u));
if(NULL == pBuf)
   // not enough memory
ippsFree(pBuf);
}

I can not really believe that also the sizeof(IppXYZ) has to be multiplied when calling the ippsMalloc_XYZ(...) function.

I guess the corrupted heap in my small programm is the result of the large adressroom
- on 64 bit platforms: sizeof(Ipp32f*) = 8 , sizeof(Ipp32f) = 4
- on 32 bit platforms: sizeof(Ipp32f*) = 4 , sizeof(Ipp32f) = 4

If I use
Ipp32f** x = (Ipp32f**)ippsMalloc_32f(19 * sizeof(Ipp32f*)/sizeof(Ipp32f));
instead of
Ipp32f** x = (Ipp32f**)ippsMalloc_32f(19);
the program works perfect on all platforms (32 and 64 bit).


Has anybody an idea what's going wrong?

0 Kudos
5 Replies
Chao_Y_Intel
Moderator
498 Views
Hello, In the 64 bit platform, the size of point is 64 bits( 8 bytes). so it should be: Ipp32f** x = (Ipp32f**)ippsMalloc_64f(19); Thanks, Chao
0 Kudos
Sergey_K_Intel
Employee
498 Views
Hi Peter, The first line of your sample is not clear. Ipp32f** x = (Ipp32f**)ippsMalloc_32f(19); If your are going to allocate room for 19 pointers to Ipp32f (19 * Ipp32f*), you should ask for at least 19*sizeof(Ipp32f*) bytes. On 32-bit system it will be 76 bytes, on 64-bit - 152 bytes. In any case the required space depends on size of pointer in you particular system. What if you got 128-bit system? )) Assumption that sizeof(Ipp32f*) is equal to sizeof(Ipp32f) is wrong. ippsMalloc_32f allocates memory for 32-bit variables only. I wouldn't use IPP allocation functions for that. Or, you can use ippsMalloc_8u(19 * sizeof(Ipp32f*)). Here, Malloc_8u is similar to conventional "malloc" function. Regards, Sergey
0 Kudos
Peter_N_1
Beginner
498 Views
Thanks for the comments. I discussed the problem again with a friend of mine. The correct way to access *PointerArrays* should be: Ipp32f** x = (Ipp32f**)malloc(19 * sizeof(Ipp32f*)); for( int i = 0; i < 19; i++ ) { x = (Ipp32f*)ippsMalloc_32f(100); for( int k = 0; k < 100; k++ ) { x = 0.0; } } ... for( int j = 0; j < 19; j++ ) { if( x != NULL ) { ippsFree(x); x = NULL; } } free(x); x = NULL;
0 Kudos
jinming_g_
Beginner
498 Views

what is the parameter 'len' referring to in ippsMalloc_XYZ(int len) function?

does it refer to "number of bytes", or "number" of elements"?

using examples on the reference:  https://software.intel.com/en-us/ipp-9.0-ipps-manual-pdf

page 35:

     Ipp8u* pBuf = ippsMalloc_8u(8*sizeof(Ipp8u));

seems referring to "number of bytes"

but the example on page 168:  

     Ipp32f *x = ippsMalloc_32f(1000), mean;
      int i;
      for(i = 0; i<1000; ++i) x = (float)rand() / RAND_MAX;

seemly referring to  "number of elements": here 'array' x has 1000 'elements', and will take 1000*sizeof(Ipp32f), or 4000 bytes!

0 Kudos
Chao_Y_Intel
Moderator
498 Views
0 Kudos
Reply