c++csolarissolaris-10

how to replace posix_memalign on Solaris 10


I have the following code which is part of the CRFsuite library. I've created an R wrapper for this library but the installation fails on Solaris 10 due to the fact that posix_memalign is not defined on Solaris 10. How does the following code (part of https://github.com/bnosac/crfsuite/blob/master/src/crf/src/vecmath.h) need to be changed in order to compile correctly on Solaris 10? FYI installation error is shown here

#include <math.h>
#include <memory.h>

#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
#include <malloc.h>
#else
#include <stdlib.h>
static inline void *_aligned_malloc(size_t size, size_t alignment)
{
    void *p;
    int ret = posix_memalign(&p, alignment, size);
    return (ret == 0) ? p : 0;
}
static inline void _aligned_free(void *p)
{
    free(p);
}
#endif

I've tried using some fixes that are made available here, but failed miserably. Hope you can help.


Solution

  • You should be able to use memalign()

    ... 
    #elif defined __SunOS_5_10
        #include <stdlib.h>
    
        static inline void *_aligned_malloc(size_t size, size_t alignment)
        {
            return memalign(alignment, size)
        }
        static inline void _aligned_free(void *p)
        {
            free(p);
        }
    #else 
     ...