本文整理汇总了C++中MyAlloc函数的典型用法代码示例。如果您正苦于以下问题:C++ MyAlloc函数的具体用法?C++ MyAlloc怎么用?C++ MyAlloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MyAlloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetTextData
/****************************************************************************
* *
* FUNCTION : GetTextData() *
* *
* PURPOSE : Allocates and returns a pointer to the data contained in *
* hData. This assumes that hData points to text data and *
* will properly handle huge text data by leaving out the *
* middle of the string and placing the size of the string *
* into this string portion. *
* *
* RETURNS : A pointer to the allocated string. *
* *
****************************************************************************/
PSTR GetTextData(
HDDEDATA hData)
{
PSTR psz;
DWORD cb;
#define CBBUF 1024
if (hData == NULL) {
return(NULL);
}
cb = DdeGetData(hData, NULL, 0, 0);
if (!hData || !cb)
return NULL;
if (cb > CBBUF) { // possibly HUGE object!
psz = MyAlloc(CBBUF);
DdeGetData(hData, psz, CBBUF - 46, 0L);
wsprintf(&psz[CBBUF - 46], "<---Size=%ld", cb);
} else {
psz = MyAlloc((WORD)cb);
DdeGetData(hData, (LPBYTE)psz, cb, 0L);
}
return psz;
#undef CBBUF
}
示例2: Free
bool CDecoder::Alloc(size_t numItems)
{
Free();
_parents = (UInt16 *)MyAlloc(numItems * sizeof(UInt16));
if (_parents == 0)
return false;
_suffixes = (Byte *)MyAlloc(numItems * sizeof(Byte));
if (_suffixes == 0)
return false;
_stack = (Byte *)MyAlloc(numItems * sizeof(Byte));
return _stack != 0;
}
示例3: AllocResLink
PRESLINK AllocResLink(
PRES pRes)
{
PRESLINK prl;
PRES pResNew;
PRES2 pRes2;
LPTSTR pszName;
INT cbName;
LPTSTR pszType;
if (!(prl = (PRESLINK)MyAlloc(sizeof(RESLINK))))
return NULL;
prl->prlNext = NULL;
prl->cbRes = ResourceSize(pRes);
if (!(prl->hRes = GlobalAlloc(GMEM_MOVEABLE, prl->cbRes))) {
MyFree(prl);
Message(MSG_OUTOFMEMORY);
return NULL;
}
pResNew = (PRES)GlobalLock(prl->hRes);
memcpy(pResNew, pRes, prl->cbRes);
GlobalUnlock(prl->hRes);
pszType = ResourceType(pRes);
if (IsOrd(pszType) && OrdID(pszType) == ORDID_RT_DIALOG) {
prl->fDlgResource = TRUE;
pszName = ResourceName(pRes);
cbName = NameOrdLen(pszName);
if (!(prl->pszName = MyAlloc(cbName))) {
GlobalFree(prl->hRes);
MyFree(prl);
return NULL;
}
NameOrdCpy(prl->pszName, pszName);
pRes2 = ResourcePart2(pRes);
prl->wLanguage = pRes2->LanguageId;
}
else {
prl->fDlgResource = FALSE;
prl->pszName = NULL;
prl->wLanguage = 0;
}
return prl;
}
示例4: GetWorkMem
//*****************************************************************
static Bool GetWorkMem()
{
// Запросить свободный блок общей памяти
// А если не дадут, то использовать
// свой кусок памяти, выделенный
// на ROUT_Init()
//
Byte *p = NULL;
long lth = 1024<<10; // 1M
p = (Byte*)MyAlloc(lth, 0);
if (!p )
{
// Использовать собственный кусок памяти
p = (Byte*)gOwnMemory;
lth = gOwnMemorySize;
DEBUG_PRINT("ROUT.CPP MyGetFreeMem: MyAlloc failed, using own memory");
}
// Установить рабочую память
INIT_MEMORY(p,lth);
return TRUE;
}
示例5: MidFree
bool CCachedInStream::Alloc(unsigned blockSizeLog, unsigned numBlocksLog)
{
unsigned sizeLog = blockSizeLog + numBlocksLog;
if (sizeLog >= sizeof(size_t) * 8)
return false;
size_t dataSize = (size_t)1 << sizeLog;
if (_data == 0 || dataSize != _dataSize)
{
MidFree(_data);
_data = (Byte *)MidAlloc(dataSize);
if (_data == 0)
return false;
_dataSize = dataSize;
}
if (_tags == 0 || numBlocksLog != _numBlocksLog)
{
MyFree(_tags);
_tags = (UInt64 *)MyAlloc(sizeof(UInt64) << numBlocksLog);
if (_tags == 0)
return false;
_numBlocksLog = numBlocksLog;
}
_blockSizeLog = blockSizeLog;
return true;
}
示例6: throw
CDynLimBuf & CDynLimBuf::operator+=(char c) throw()
{
if (_error)
return *this;
if (_size == _pos)
{
size_t n = _sizeLimit - _size;
if (n == 0)
{
_error = true;
return *this;
}
if (n > _size)
n = _size;
n += _pos;
Byte *newBuf = (Byte *)MyAlloc(n);
if (!newBuf)
{
_error = true;
return *this;
}
memcpy(newBuf, _chars, _pos);
MyFree(_chars);
_chars = newBuf;
_size = n;
}
_chars[_pos++] = c;
return *this;
}
示例7: GetFormatName
/****************************************************************************
* *
* FUNCTION : GetFormatName() *
* *
* PURPOSE : allocates and returns a pointer to a string representing *
* a format. Use MyFree() to free this string. *
* *
* RETURNS : The number of characters copied into lpstr or 0 on error. *
* *
****************************************************************************/
PSTR GetFormatName(
WORD wFmt)
{
PSTR psz;
WORD cb;
if (wFmt == 1) {
psz = MyAlloc(8);
strcpy(psz, "CF_TEXT");
return psz;
}
psz = MyAlloc(255);
*psz = '\0';
cb = GetClipboardFormatName(wFmt, psz, 255) + 1;
return((PSTR)LocalReAlloc((HANDLE)psz, cb, LMEM_MOVEABLE));
}
示例8: init_foods
void init_foods(void)
{
ULONG i;
foods = (struct Food *) MyAlloc(MAX_FOODS * sizeof(struct Food));
memset(foods,0,sizeof(struct Food)*MAX_FOODS);
for (i=0; i<MAX_FOODS; i++)
foods[i].Head = -1;
}
示例9: main
int main()
{
char buffer2[20];
char buffer3[20];
void * al;
void *toout,*fromout;
int page_size = getpagesize();
page_mask = ~((intptr_t)page_size-1);
// Get some page aligned memory
void * x = malloc(page_size * 2);
target_space = ((intptr_t)x + page_size - 1) & page_mask;
void * mm = (void*)target_space;
al = MyAlloc(mm); // cause the swizzle
swizzle_space = (intptr_t)al & page_mask;
if (swizzle_space == target_space)
{
fprintf (stderr,"Error al not swizzled\n");
}
((char*)al)[0] = 1;
buffer2[0] = 2;
buffer3[0] = 3;
mmemcpy(buffer2, al, n, &toout, &fromout);
fprintf(stderr, "al[0] %d buffer2[0] %d toout - to %x fromout - from %x\n",
((char*)al)[0], buffer2[0],
(char*)toout - (char*)buffer2, (char*)fromout- (char*)al);
if (!Swizzled (al)) {
fprintf (stderr,"Error1 al not swizzled\n");
}
if (!Swizzled (fromout)) {
fprintf (stderr,"Error2 fromout not swizzled\n");
}
mmemcpy(al, buffer3, n, &toout, &fromout);
if (!Swizzled (al)) {
fprintf (stderr,"Error3 al not swizzled\n");
fflush (stderr);
}
if (!Swizzled (toout)) {
fprintf (stderr,"Error4 toout not swizzled\n");
fflush (stderr);
}
fprintf(stderr, "al[0] %d buffer3[0] %d toout - to %x fromout - from %x\n",((char*)al)[0],
buffer3[0], (char*)toout-(char *)al, (char*)fromout - (char*)buffer3);
fflush (stderr);
memindex(al);
MyFree(al);
return 0;
}
示例10: Free
bool CEncoder::Create(UInt32 numSymbols,
const Byte *extraBits, UInt32 extraBase, UInt32 maxLength)
{
m_NumSymbols = numSymbols;
m_ExtraBits = extraBits;
m_ExtraBase = extraBase;
m_MaxLength = maxLength;
m_HeapSize = numSymbols * 2 + 1;
Free();
m_Items = (CItem *)MyAlloc(m_HeapSize * sizeof(CItem));
m_Heap = (UInt32 *)MyAlloc(m_HeapSize * sizeof(UInt32));
m_Depth = (Byte *)MyAlloc(m_HeapSize * sizeof(Byte));
if (m_Items == 0 || m_Heap == 0 || m_Depth == 0)
{
Free();
return false;
}
return true;
}
示例11: CreateInputBuffer
HRESULT CDecoder::CreateInputBuffer()
{
if (_inBuf == 0)
{
_inBuf = (Byte *)MyAlloc(kInBufSize);
if (_inBuf == 0)
return E_OUTOFMEMORY;
}
return S_OK;
}
示例12: MyFree
HRESULT CDecoder::CreateInputBuffer()
{
if (_inBuf == 0 || _inBufSize != _inBufSizeAllocated)
{
MyFree(_inBuf);
_inBuf = (Byte *)MyAlloc(_inBufSize);
if (_inBuf == 0)
return E_OUTOFMEMORY;
_inBufSizeAllocated = _inBufSize;
}
return S_OK;
}
示例13: RINOK
STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *prop, UInt32 size)
{
RINOK(SResToHRESULT(LzmaDec_Allocate(&_state, prop, size, &g_Alloc)));
if (_inBuf == 0)
{
_inBuf = (Byte *)MyAlloc(kInBufSize);
if (_inBuf == 0)
return E_OUTOFMEMORY;
}
return S_OK;
}
示例14: RINOK
STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *prop, UInt32 size)
{
if (size != 1) return SZ_ERROR_UNSUPPORTED;
RINOK(SResToHRESULT(Lzma2Dec_Allocate(&_state, prop[0], &g_Alloc)));
if (_inBuf == 0)
{
_inBuf = (Byte *)MyAlloc(kInBufSize);
if (_inBuf == 0)
return E_OUTOFMEMORY;
}
return S_OK;
}
示例15: MyAlloc
WCHAR *MyMakeStr(WCHAR *s)
{
WCHAR * s1;
if (s) {
s1 = (WCHAR *) MyAlloc((wcslen(s) + 1) * sizeof(WCHAR)); /* allocate buffer */
wcscpy(s1, s); /* copy string */
}
else
s1 = s;
return(s1);
}