Leaked source code of windows server 2003
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.

104 lines
2.0 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_PTR Size, IN DWORD_PTR 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_PTR stringLength;
  45. PSTR rString;
  46. assert(StringToCopy);
  47. stringLength = strlen(StringToCopy)+1;
  48. rString = (PSTR) PoolMemGetAlignedMemory(Handle,
  49. stringLength,
  50. sizeof(CHAR));
  51. if (rString) {
  52. _mbscpy((unsigned char *) rString, (const unsigned char *) StringToCopy);
  53. }
  54. return rString;
  55. }
  56. __inline
  57. PWSTR
  58. PoolMemDuplicateStringW (
  59. IN POOLHANDLE Handle,
  60. IN LPCWSTR StringToCopy
  61. )
  62. {
  63. DWORD stringLength;
  64. PWSTR rString;
  65. assert(StringToCopy);
  66. stringLength = ((wcslen(StringToCopy)+1)*sizeof(WCHAR));
  67. rString = (PWSTR) PoolMemGetAlignedMemory(Handle,stringLength,sizeof(WCHAR));
  68. if (rString) {
  69. wcscpy(rString,StringToCopy);
  70. }
  71. return rString;
  72. }
  73. #endif