📄 functions.h
字号:
}
}
else
{
STLSOFT_NS_GLOBAL(SetLastError)(stlsoft_static_cast(DWORD, hr));
pvNew = NULL;
}
return pvNew;
}
/** \brief [C only] Gives the size of a memory block
*
* \ingroup group__library__memory
*
* This function returns the size of a memory block relative to the COM task
* alloctor, as per <code>IMalloc::GetSize()</code>
*
* \param pv Pointer to the memory block
* \return The size of the memory block (in bytes)
*
* \note [C++] This function is wrapped by the winstl::SHMemGetSize()
* function.
*/
STLSOFT_INLINE ws_size_t winstl__SHMemGetSize(void *pv)
{
LPMALLOC lpmalloc;
ws_size_t ulRet;
HRESULT hr = STLSOFT_NS_GLOBAL(SHGetMalloc)(&lpmalloc);
if(SUCCEEDED(hr))
{
ulRet = WINSTL_ITF_CALL(lpmalloc)->GetSize(WINSTL_ITF_THIS(lpmalloc) pv);
WINSTL_ITF_CALL(lpmalloc)->Release(WINSTL_ITF_THIS0(lpmalloc));
}
else
{
STLSOFT_NS_GLOBAL(SetLastError)(stlsoft_static_cast(DWORD, hr));
ulRet = 0;
}
return ulRet;
}
/** \brief [C only] Determines allocation ownership of a memory block
*
* \ingroup group__library__memory
*
* This function returns a value indicating whether a memory block was allocated
* by the COM task allocator, as per <code>IMalloc::DidAlloc()</code>
*
* \param pv Pointer to the memory block
* \return Result indicating ownership
* \retval 1 The memory block was allocated by the task allocator
* \retval 0 The memory block was <i>not</i> allocated by the task allocator
* \retval -1 SHMemDidAlloc() cannot determine whether the memory block was allocated by the task allocator
*
* \note [C++] This function is wrapped by the winstl::SHMemDidAlloc()
* function.
*/
STLSOFT_INLINE ws_sint_t winstl__SHMemDidAlloc(void *pv)
{
LPMALLOC lpmalloc;
ws_sint_t iRet;
HRESULT hr = STLSOFT_NS_GLOBAL(SHGetMalloc)(&lpmalloc);
if(SUCCEEDED(hr))
{
iRet = WINSTL_ITF_CALL(lpmalloc)->DidAlloc(WINSTL_ITF_THIS(lpmalloc) pv);
WINSTL_ITF_CALL(lpmalloc)->Release(WINSTL_ITF_THIS0(lpmalloc));
}
else
{
STLSOFT_NS_GLOBAL(SetLastError)(stlsoft_static_cast(DWORD, hr));
iRet = -1;
}
return iRet;
}
/** \brief [C only] Minimises the heap
*
* \ingroup group__library__memory
*
* This function minimises the heap as much as possible by releasing unused
* memory to the operating system, coalescing adjacent free blocks and
* committing free pages, as as per <code>IMalloc::HeapMinimize()</code>.
*
* \note [C++] This function is wrapped by the winstl::SHMemHeapMinimise()
* function.
*/
STLSOFT_INLINE void winstl__SHMemHeapMinimise(void)
{
LPMALLOC lpmalloc;
HRESULT hr = STLSOFT_NS_GLOBAL(SHGetMalloc)(&lpmalloc);
if(SUCCEEDED(hr))
{
WINSTL_ITF_CALL(lpmalloc)->HeapMinimize(WINSTL_ITF_THIS0(lpmalloc));
WINSTL_ITF_CALL(lpmalloc)->Release(WINSTL_ITF_THIS0(lpmalloc));
}
else
{
STLSOFT_NS_GLOBAL(SetLastError)(stlsoft_static_cast(DWORD, hr));
}
}
/* /////////////////////////////////////////////////////////////////////////
* Namespace
*/
#ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
namespace winstl
{
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* C++ functions
*/
#ifdef __cplusplus
/** \brief Allocates a block of shell memory.
*
* \ingroup group__library__memory
*
* This function is a wrapper for winstl__SHMemAlloc().
*
* \param cb The size, in bytes, of the memory block to be allocated.
* \return Pointer to the allocated memory block, or NULL if the request
* failed.
*/
inline void *SHMemAlloc(ws_size_t cb)
{
return winstl__SHMemAlloc(cb);
}
/** \brief Deallocates a block of shell memory.
*
* \ingroup group__library__memory
*
* This function is a wrapper for winstl__SHMemFree().
*
* \param pv Pointer to the memory block to be deallocated
*/
inline void SHMemFree(void *pv)
{
winstl__SHMemFree(pv);
}
/** \brief Changes the size of a previously allocated block of shell memory.
*
* \ingroup group__library__memory
*
* This function is a wrapper for winstl__SHMemRelloc().
*
* \param pv Pointer to the memory block to be reallocated. Can be NULL, in
* which case the function acts like SHMemAlloc()
* \param cb The size, in bytes, of the memory block to be reallocated. Can
* be 0, in which case the function acts like SHMemFree() (if pv is not
* NULL), or like SHMemAlloc() (if pv is NULL).
* \return Pointer to the allocated memory block, or NULL if the request
* failed or cb is 0 and pv is not NULL.
*/
inline void *SHMemRealloc(void *pv, ws_size_t cb)
{
return winstl__SHMemRealloc(pv, cb);
}
/** \brief Gives the size of a memory block
*
* \ingroup group__library__memory
*
* This function is a wrapper for winstl__SHMemGetSize().
*
* \param pv Pointer to the memory block
* \return The size of the memory block (in bytes)
*/
inline ws_size_t SHMemGetSize(void *pv)
{
return winstl__SHMemGetSize(pv);
}
/** \brief Determines allocation ownership of a memory block
*
* \ingroup group__library__memory
*
* This function is a wrapper for winstl__SHMemDidAlloc().
*
* \param pv Pointer to the memory block
* \return Result indicating ownership
* \retval 1 The memory block was allocated by the task allocator
* \retval 0 The memory block was <i>not</i> allocated by the task allocator
* \retval -1 SHMemDidAlloc() cannot determine whether the memory block was allocated by the task allocator
*/
inline ws_sint_t SHMemDidAlloc(void *pv)
{
return winstl__SHMemDidAlloc(pv);
}
/** \brief Minimises the heap
*
* \ingroup group__library__memory
*
* This function is a wrapper for winstl__SHMemHeapMinimise().
*/
inline void SHMemHeapMinimise()
{
winstl__SHMemHeapMinimise();
}
/** \brief Minimises the heap
*
* \ingroup group__library__memory
*
* This function is a wrapper for winstl__SHMemHeapMinimise().
*/
inline void SHMemHeapMinimize()
{
winstl__SHMemHeapMinimise();
}
#endif /* __cplusplus */
/* /////////////////////////////////////////////////////////////////////////
* Unit-testing
*/
#ifdef STLSOFT_UNITTEST
# include "./unittest/functions_unittest_.h"
#endif /* STLSOFT_UNITTEST */
/* ////////////////////////////////////////////////////////////////////// */
#ifndef _WINSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} /* namespace winstl */
# else
} /* namespace stlsoft::winstl_project */
} /* namespace stlsoft */
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* !WINSTL_INCL_WINSTL_SHELL_MEMORY_H_FUNCTIONS */
/* ////////////////////////////////////////////////////////////////////// */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -