~ubuntu-branches/ubuntu/utopic/r-cran-rcpparmadillo/utopic

« back to all changes in this revision

Viewing changes to inst/include/armadillo_bits/memory.hpp

  • Committer: Package Import Robot
  • Author(s): Dirk Eddelbuettel
  • Date: 2013-12-09 18:13:21 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20131209181321-cc9ycvs53xfiz5ow
Tags: 0.3.930.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
  
17
17
                        arma_inline             static uword enlarge_to_mult_of_chunksize(const uword n_elem);
18
18
  
19
 
  template<typename eT> arma_inline arma_malloc static eT*   acquire(const uword n_elem);
 
19
  template<typename eT>      inline arma_malloc static eT*   acquire(const uword n_elem);
20
20
  
21
 
  template<typename eT> arma_inline arma_malloc static eT*   acquire_chunked(const uword n_elem);
 
21
  template<typename eT>      inline arma_malloc static eT*   acquire_chunked(const uword n_elem);
22
22
  
23
23
  template<typename eT> arma_inline             static void  release(eT* mem);
24
24
  
45
45
 
46
46
 
47
47
template<typename eT>
48
 
arma_inline
 
48
inline
49
49
arma_malloc
50
50
eT*
51
51
memory::acquire(const uword n_elem)
52
52
  {
 
53
  eT* out_memptr;
 
54
  
53
55
  #if   defined(ARMA_USE_TBB_ALLOC)
54
56
    {
55
 
    return ( (eT *) scalable_malloc(sizeof(eT)*n_elem) );
 
57
    out_memptr = (eT *) scalable_malloc(sizeof(eT)*n_elem);
56
58
    }
57
59
  #elif defined(ARMA_USE_MKL_ALLOC)
58
60
    {
59
 
    return ( (eT *) mkl_malloc( sizeof(eT)*n_elem, 128 ) );
 
61
    out_memptr = (eT *) mkl_malloc( sizeof(eT)*n_elem, 128 );
60
62
    }
61
63
  #elif defined(ARMA_HAVE_POSIX_MEMALIGN)
62
64
    {
66
68
    
67
69
    int status = posix_memalign((void **)&memptr, ( (alignment >= sizeof(void*)) ? alignment : sizeof(void*) ), sizeof(eT)*n_elem);
68
70
    
69
 
    return (status == 0) ? memptr : NULL;
 
71
    out_memptr = (status == 0) ? memptr : NULL;
70
72
    }
71
73
  #elif defined(_MSC_VER)
72
74
    {
73
 
    return ( (eT *) _aligned_malloc( sizeof(eT)*n_elem, 16 ) );  // lives in malloc.h
 
75
    out_memptr = (eT *) _aligned_malloc( sizeof(eT)*n_elem, 16 );  // lives in malloc.h
74
76
    }
75
77
  #else
76
78
    {
77
79
    //return ( new(std::nothrow) eT[n_elem] );
78
 
    return ( (eT *) malloc(sizeof(eT)*n_elem) );
 
80
    out_memptr = (eT *) malloc(sizeof(eT)*n_elem);
79
81
    }
80
82
  #endif
81
83
  
82
84
  // TODO: for mingw, use __mingw_aligned_malloc
 
85
  
 
86
  if(n_elem > 0)
 
87
    {
 
88
    arma_check_bad_alloc( (out_memptr == NULL), "arma::memory::acquire(): out of memory" );
 
89
    }
 
90
  
 
91
  return out_memptr;
83
92
  }
84
93
 
85
94
 
86
95
 
87
96
//! get memory in multiples of chunks, holding at least n_elem
88
97
template<typename eT>
89
 
arma_inline
 
98
inline
90
99
arma_malloc
91
100
eT*
92
101
memory::acquire_chunked(const uword n_elem)