Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
1.8 KiB

  1. #ifndef POOLMEM_H
  2. #define POOLMEM_H
  3. typedef LPVOID POOLHANDLE;
  4. #define POOLMEMORYBLOCKSIZE 8192
  5. POOLHANDLE WINAPI PoolMemInitPool ();
  6. VOID WINAPI PoolMemDestroyPool (IN POOLHANDLE Handle);
  7. LPVOID WINAPI PoolMemGetAlignedMemory(IN POOLHANDLE Handle, IN DWORD Size, IN DWORD AlignSize);
  8. #define PoolMemCreateString(h,x) ((LPTSTR) PoolMemGetAlignedMemory((h),(x)*sizeof(TCHAR)))
  9. #define PoolMemCreateDword(h) ((PDWORD) PoolMemGetMemory((h),sizeof(DWORD)))
  10. __inline
  11. LPVOID
  12. PoolMemGetMemory (
  13. IN POOLHANDLE Handle,
  14. IN DWORD Size
  15. )
  16. {
  17. return PoolMemGetAlignedMemory(Handle,Size,0);
  18. }
  19. __inline
  20. LPTSTR
  21. PoolMemCreateStringA (
  22. IN POOLHANDLE Handle,
  23. IN DWORD Size
  24. )
  25. {
  26. return (LPSTR) PoolMemGetAlignedMemory(Handle,Size * sizeof(CHAR),sizeof(CHAR));
  27. }
  28. __inline
  29. LPWSTR
  30. PoolMemCreateStringW (
  31. IN POOLHANDLE Handle,
  32. IN DWORD Size
  33. )
  34. {
  35. return (LPWSTR) PoolMemGetAlignedMemory(Handle,Size * sizeof(WCHAR),sizeof(WCHAR));
  36. }
  37. __inline
  38. PTSTR
  39. PoolMemDuplicateStringA (
  40. IN POOLHANDLE Handle,
  41. IN LPCSTR StringToCopy
  42. )
  43. {
  44. DWORD stringLength;
  45. PSTR rString;
  46. assert(StringToCopy);
  47. stringLength = (DWORD) _mbschr(StringToCopy,0) - (DWORD) StringToCopy + 1;
  48. rString = PoolMemGetAlignedMemory(Handle,stringLength,sizeof(CHAR));
  49. if (rString) {
  50. _mbscpy(rString,StringToCopy);
  51. }
  52. return rString;
  53. }
  54. __inline
  55. PWSTR
  56. PoolMemDuplicateStringW (
  57. IN POOLHANDLE Handle,
  58. IN LPCWSTR StringToCopy
  59. )
  60. {
  61. DWORD stringLength;
  62. PWSTR rString;
  63. assert(StringToCopy);
  64. stringLength = ((wcslen(StringToCopy)+1)*sizeof(WCHAR));
  65. rString = PoolMemGetAlignedMemory(Handle,stringLength,sizeof(WCHAR));
  66. if (rString) {
  67. wcscpy(rString,StringToCopy);
  68. }
  69. return rString;
  70. }
  71. #endif