• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ MyAlloc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中MyAlloc函数的典型用法代码示例。如果您正苦于以下问题:C++ MyAlloc函数的具体用法?C++ MyAlloc怎么用?C++ MyAlloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了MyAlloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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    
}
开发者ID:chunhualiu,项目名称:OpenNT,代码行数:40,代码来源:dde.c


示例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;
}
开发者ID:Ando02,项目名称:wubiuefi,代码行数:12,代码来源:ZDecoder.cpp


示例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;
}
开发者ID:mingpen,项目名称:OpenNT,代码行数:51,代码来源:reslist.c


示例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;

}
开发者ID:PauloMigAlmeida,项目名称:cuneiform,代码行数:27,代码来源:rout.cpp


示例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;
}
开发者ID:BenjaminSiskoo,项目名称:mame,代码行数:25,代码来源:StreamObjects.cpp


示例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;
}
开发者ID:670232921,项目名称:pfm_archive,代码行数:31,代码来源:DynLimBuf.cpp


示例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));
}
开发者ID:chunhualiu,项目名称:OpenNT,代码行数:26,代码来源:dde.c


示例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;
}
开发者ID:elbeno,项目名称:snakes,代码行数:9,代码来源:food.c


示例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;
}
开发者ID:gungun1010,项目名称:hidden,代码行数:57,代码来源:swizzlealloc.c


示例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;
}
开发者ID:OPSF,项目名称:uClinux,代码行数:19,代码来源:HuffmanEncoder.cpp


示例11: CreateInputBuffer

HRESULT CDecoder::CreateInputBuffer()
{
  if (_inBuf == 0)
  {
    _inBuf = (Byte *)MyAlloc(kInBufSize);
    if (_inBuf == 0)
      return E_OUTOFMEMORY;
  }
  return S_OK;
}
开发者ID:LTears,项目名称:rktotal,代码行数:10,代码来源:LzmaDecoder.cpp


示例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;
}
开发者ID:SaketaChalamchala,项目名称:DisassemblyAccuracy,代码行数:12,代码来源:LzmaDecoder.cpp


示例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;
}
开发者ID:Dark1X,项目名称:u-boot_mod,代码行数:13,代码来源:LzmaDecoder.cpp


示例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;
}
开发者ID:0vermind,项目名称:NeoLoader,代码行数:13,代码来源:Lzma2Decoder.cpp


示例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);
}
开发者ID:mingpen,项目名称:OpenNT,代码行数:13,代码来源:rcutil.c


示例16: MyCopyAll

int     MyCopyAll(FILE *srcfh, PFILE dstfh)
{
    PCHAR  buffer = MyAlloc(BUFSIZE);

    UINT n;

    while ((n = fread(buffer, 1, BUFSIZE, srcfh)) != 0)
        MyWrite(dstfh, buffer, n);

    MyFree(buffer);

    return TRUE;
}
开发者ID:mingpen,项目名称:OpenNT,代码行数:13,代码来源:rcutil.c


示例17: TestSuite_sboot_c_7608004f_TestSuite_MyAlloc

/* CPPTEST_TEST_CASE_CONTEXT void * MyAlloc(size_t) */
void TestSuite_sboot_c_7608004f_TestSuite_MyAlloc()
{
    /* Pre-condition initialization */
    /* Initializing argument 1 (size) */



    size_t _size  = 0u;
    {
        /* Tested function call */
        void * _return  = MyAlloc(_size);
        /* Post-condition check */
        CPPTEST_POST_CONDITION_PTR("void * _return ", ( _return ));
    }
}
开发者ID:Scorpio92,项目名称:mstar6a918,代码行数:16,代码来源:TestSuite_sboot_c.c


示例18: NameOrdDup

LPTSTR NameOrdDup(
    LPTSTR pNameOrd)
{
    register INT iLen;
    LPTSTR psz;

    iLen = NameOrdLen(pNameOrd);

    if (!(psz = (LPTSTR)MyAlloc(iLen)))
        return NULL;

    NameOrdCpy(psz, pNameOrd);

    return psz;
}
开发者ID:mingpen,项目名称:OpenNT,代码行数:15,代码来源:resutil.c


示例19: ROUT_FUNC

//********************************************************************
ROUT_FUNC(Bool32) ROUT_Init(uint16_t wHighCode,HANDLE hStorage)
{
//	DEBUG_PRINT("ROUT_Init(%d,%d)",wHighCode,hStorage);

	gwHighRC_rout = wHighCode;
	ghStorage_rout = hStorage;
	gwLowRC_rout = 0;

	// Собственный кусок памяти на одну страницу
	gOwnMemory = MyAlloc(gOwnMemorySize,0);
	if ( !gOwnMemory )
		NO_MEMORY;

	return ROUT_GetReturnCode()==0? TRUE:FALSE;
}
开发者ID:PauloMigAlmeida,项目名称:cuneiform,代码行数:16,代码来源:rout_dll.cpp


示例20: ROUT_GetObjectSize

//********************************************************************
uint32_t ROUT_GetObjectSize(
        uint32_t objIndex	// Индекс объекта начиная от 1
        )
{
    // Гадкая функция для определения длины объекта
    Byte *p = NULL;
    long lth = 256<<10;		// 256K
    long sizeMem = 0;

    ClearError();

    for (long attempt = 1; attempt < 3; attempt++)
    {
        p = (Byte*)MyAlloc(lth,0);
        if (!p)
        {
            NO_MEMORY;
            return 0;
        }

        InitMemory(p,lth);

        // Выполнить конвертирование на памяти
        sizeMem = lth;
        if ( ROUT_GetObject(
                objIndex,
                0,	// lpMem
                &sizeMem)	// sizeMem
            )
            {
            FreeWorkMem();
            return sizeMem + 2*gBumperSize;
        }

        // Повторить попытку с большей памятью
        FreeWorkMem();
        lth = lth <<1 ;
    }

    return 0;	// Неудача
}
开发者ID:PauloMigAlmeida,项目名称:cuneiform,代码行数:42,代码来源:rout.cpp



注:本文中的MyAlloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ MyClient函数代码示例发布时间:2022-05-30
下一篇:
C++ My402ListFirst函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap