lbnmem.h
上传用户:zbbssh
上传日期:2007-01-08
资源大小:196k
文件大小:2k
源码类别:

CA认证

开发平台:

C/C++

  1. /*
  2.  * Operations on the usual buffers of bytes
  3.  */
  4. #ifndef BNSECURE
  5. #define BNSECURE 1
  6. #endif
  7. /*
  8.  * These operations act on buffers of memory, just like malloc & free.
  9.  * One exception: it is not legal to pass a NULL pointer to lbnMemFree.
  10.  */
  11. #ifndef lbnMemAlloc
  12. void *lbnMemAlloc(unsigned bytes);
  13. #endif
  14. #ifndef lbnMemFree
  15. void lbnMemFree(void *ptr, unsigned bytes);
  16. #endif
  17. /* This wipes out a buffer of bytes if necessary needed. */
  18. #ifndef lbnMemWipe
  19. #if BNSECURE
  20. void lbnMemWipe(void *ptr, unsigned bytes);
  21. #else
  22. #define lbnMemWipe(ptr, bytes) (void)(ptr,bytes)
  23. #endif
  24. #endif /* !lbnMemWipe */
  25. /*
  26.  * lbnRealloc is NOT like realloc(); it's endian-sensitive
  27.  * If lbnMemRealloc is #defined, lbnRealloc will be defined in terms of it.
  28.  * It is legal to pass a NULL pointer to lbnRealloc, although oldbytes
  29.  * will always be sero.
  30.  */
  31. #ifndef lbnRealloc
  32. void *lbnRealloc(void *ptr, unsigned oldbytes, unsigned newbytes);
  33. #endif
  34. /*
  35.  * These macros are the ones actually used most often in the math library.
  36.  * They take and return pointers to the *end* of the given buffer, and
  37.  * take sizes in terms of words, not bytes.
  38.  *
  39.  * Note that LBNALLOC takes the pointer as an argument instead of returning
  40.  * the value.
  41.  *
  42.  * Note also that these macros are only useable if you have included
  43.  * lbn.h (for the BIG and BIGLITTLE macros), which this file does NOT include.
  44.  */
  45. #define LBNALLOC(p,words) BIGLITTLE( 
  46. if ( ((p) = lbnMemAlloc((words)*sizeof*(p))) != 0) (p) += (words), 
  47. (p) = lbnMemAlloc((words) * sizeof*(p)) 
  48. )
  49. #define LBNFREE(p,words) lbnMemFree((p) BIG(-(words)), (words) * sizeof*(p))
  50. #define LBNREALLOC(p,old,new) 
  51. lbnRealloc(p, (old) * sizeof*(p), (new) * sizeof*(p))
  52. #define LBNWIPE(p,words) lbnMemWipe((p) BIG(-(words)), (words) * sizeof*(p))