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.

116 lines
2.0 KiB

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