- Code/Resource
- Windows Develop
- Linux-Unix program
- Internet-Socket-Network
- Web Server
- Browser Client
- Ftp Server
- Ftp Client
- Browser Plugins
- Proxy Server
- Email Server
- Email Client
- WEB Mail
- Firewall-Security
- Telnet Server
- Telnet Client
- ICQ-IM-Chat
- Search Engine
- Sniffer Package capture
- Remote Control
- xml-soap-webservice
- P2P
- WEB(ASP,PHP,...)
- TCP/IP Stack
- SNMP
- Grid Computing
- SilverLight
- DNS
- Cluster Service
- Network Security
- Communication-Mobile
- Game Program
- Editor
- Multimedia program
- Graph program
- Compiler program
- Compress-Decompress algrithms
- Crypt_Decrypt algrithms
- Mathimatics-Numerical algorithms
- MultiLanguage
- Disk/Storage
- Java Develop
- assembly language
- Applications
- Other systems
- Database system
- Embeded-SCM Develop
- FlashMX/Flex
- source in ebook
- Delphi VCL
- OS Develop
- MiddleWare
- MPI
- MacOS develop
- LabView
- ELanguage
- Software/Tools
- E-Books
- Artical/Document
MEMORY.CPP
Package: MSDN_VC98.zip [view]
Upload User: bangxh
Upload Date: 2007-01-31
Package Size: 42235k
Code Size: 3k
Category:
Windows Develop
Development Platform:
Visual C++
- /*++
- Copyright (c) 1996 Microsoft Corporation
- Module Name:
- Memory.cpp
- Abstract:
- This module provides all the memory management functions for all Sample
- provider components
- Author:
- Environment:
- User mode
- Revision History :
- --*/
- #include "adssmp.h"
- #define WORD_ALIGN_DOWN(addr) ((LPBYTE)((DWORD)addr &= ~1))
- #define DWORD_ALIGN_UP(size) ((size+3)&~3)
- LPVOID
- AllocProvMem(
- DWORD cb
- )
- {
- LPDWORD pMem;
- DWORD cbNew ;
- #if DBG
- cb = DWORD_ALIGN_UP(cb);
- cbNew = cb + (sizeof(DWORD) + sizeof(LONGLONG));
- #else
- cbNew = cb ;
- #endif
- pMem=(LPDWORD)LocalAlloc(LPTR, cbNew);
- #if DBG
- if (!pMem) {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return 0;
- }
- *pMem=cb;
- *(LPDWORD)((LPBYTE)pMem+cbNew-sizeof(DWORD))=0xdeadfeed;
- pMem = (LPDWORD) (((LPBYTE)pMem)+sizeof(LONGLONG));
- #endif
- return (LPVOID)(pMem);
- }
- BOOL
- FreeProvMem(
- LPVOID pMem
- )
- {
- LPBYTE pNewMem;
- pNewMem = (LPBYTE)pMem;
- #if DBG
- DWORD cb;
- DWORD cbNew = 0;
- pNewMem -= sizeof(LONGLONG) ;
- cb = *((LPDWORD)pNewMem);
- cbNew = cb + sizeof(DWORD) + sizeof(LONGLONG);
- if (*(LPDWORD)(pNewMem + cbNew - sizeof(DWORD)) != 0xdeadbeef) {
- ADsAssert(!"Freeing memory not allocated by AllocProvMem") ;
- return FALSE;
- }
- // fill freed memory with known pattern
- memset(pMem, 0x5C, cb);
- #endif
- return(LocalFree((LPVOID)pNewMem) == NULL);
- }
- LPVOID
- ReallocProvMem(
- LPVOID pOldMem,
- DWORD cbOld,
- DWORD cbNew
- )
- {
- LPVOID pNewMem;
- pNewMem=AllocProvMem(cbNew);
- if (pOldMem && pNewMem) {
- memcpy(pNewMem, pOldMem, min(cbNew, cbOld));
- FreeProvMem(pOldMem);
- }
- return pNewMem;
- }
- LPWSTR
- AllocProvStr(
- LPWSTR pStr
- )
- {
- LPWSTR pMem;
- if (!pStr)
- return 0;
- if (pMem = (LPWSTR)AllocProvMem( wcslen(pStr)*sizeof(WCHAR) + sizeof(WCHAR) ))
- wcscpy(pMem, pStr);
- return pMem;
- }
- BOOL
- FreeProvStr(
- LPWSTR pStr
- )
- {
- return pStr ? FreeProvMem(pStr)
- : FALSE;
- }
- BOOL
- ReallocProvStr(
- LPWSTR *ppStr,
- LPWSTR pStr
- )
- {
- FreeProvStr(*ppStr);
- *ppStr=AllocProvStr(pStr);
- return TRUE;
- }
- STDAPI
- ProvAllocString(const OLECHAR * pch, BSTR * pBSTR)
- {
- HRESULT hr = S_OK;
- ADsAssert(pBSTR);
- if (!pch)
- {
- *pBSTR = NULL;
- return S_OK;
- }
- *pBSTR = SysAllocString(pch);
- hr = (*pBSTR) ? S_OK : E_OUTOFMEMORY;
- RRETURN(hr);
- }