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

C++ NewPtr函数代码示例

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

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



在下文中一共展示了NewPtr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: WindowRegisterTXNScrollProcs

OSStatus
WindowRegisterTXNScrollProcs( WindowRef window, TXNObject txnObj )
{
    OSStatus status = memFullErr;
    ControlRef aScrollControl;
    ControlRef* pScrollControl;
    ControlID controlID = { kMyVerticalScrollBar, 0 };
    
    // allocate memory to hold scroll controls
    Ptr scrollControlArray = NewPtr( sizeof(ControlRef) * 2 ); // don't forget to dispose when finished
    require( scrollControlArray != NULL, MemoryError );
    
    // pointer to first ControlRef in array
    pScrollControl = (ControlRef*)scrollControlArray;
    
    // set up and store vertical scroll control
    status = GetControlByID( window, &controlID, &aScrollControl );
    require_noerr( status, CantSetupControl );
    status = ControlRegisterActionProc( window, aScrollControl, kTXNVertical );
    require_noerr( status, CantSetupControl );
                            
    *pScrollControl = aScrollControl;
    
    // advance to next ControlRef in array
    pScrollControl++;
    
    // set up and store horizontal scroll control
    controlID.signature = kMyHorizontalScrollBar;
    status = GetControlByID( window, &controlID, &aScrollControl);
    require_noerr( status, CantSetupControl );
    status = ControlRegisterActionProc( window, aScrollControl, kTXNHorizontal );
    require_noerr( status, CantSetupControl );
    *pScrollControl = aScrollControl;
    
    // The scroll info proc is MLTE's way to tell you that the content of
    // the TXNObject has changed and that the scrollbars should be updated
    // We need a way to find the controlRefs to our scroll controls while inside the callback.
    // One way to do that is just put a pointer to an array of controlRefs inside the userData
    // item for the callback.  (You could also put a pointer to your own struct/class instance)
    if( scrollControlArray != NULL )
    {
        gScrollInfoUPP = NewTXNScrollInfoUPP( MyMLTEScrollInfoCallback );
        require( gScrollInfoUPP != NULL, CantMakeScrollUPP );
        TXNRegisterScrollInfoProc( txnObj, gScrollInfoUPP, (SInt32)scrollControlArray/*userData*/);
    }
    
    MemoryError:
    return status;
    
    // clean up allocated memory if jumped to here
    CantSetupControl:
    CantMakeScrollUPP:
    DisposePtr( scrollControlArray );
    return status;
    
}
开发者ID:fruitsamples,项目名称:MLTE_CustomScrolling,代码行数:56,代码来源:SampleTXNScrollCode.cpp


示例2: _heap_grow_emptylist

static int __cdecl _heap_grow_emptylist (
        void
        )
{
        REG1 _PBLKDESC first;
        REG2 _PBLKDESC next;
        _PBLKDESC last;


        /*
         * Get memory for the new empty heap descriptors
         *
         * Note that last is used to hold the returned pointer because
         * first (and next) are register class.
         */

        if ((last = (_PBLKDESC)NewPtr(_HEAP_EMPTYLIST_SIZE)) == NULL)
                {
                return 0;
                }

        /*
         * Init the empty heap descriptor list.
         */

        _heap_desc.emptylist = first = last;


        /*
         * Carve the memory into an empty list
         */

        last = (_PBLKDESC) ((char *) first + _HEAP_EMPTYLIST_SIZE - sizeof(_BLKDESC));
        next = (_PBLKDESC) ((char *) first + sizeof(_BLKDESC));

        while ( first < last ) {

                /* Init this descriptor */
                first->pnextdesc = next;

                /* onto the next block */

                first = next++;

        }

        /*
         * Take care of the last descriptor (end of the empty list)
         */

        last->pnextdesc = NULL;


        return 1;

}
开发者ID:Trietptm-on-Coding-Algorithms,项目名称:CodeLibrary,代码行数:56,代码来源:HEAPINIT.C


示例3: CFStringToCString

char *
CFStringToCString(CFStringRef input)
{
	if (input == NULL)
		return NULL;
	int strlen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(input), kCFStringEncodingUTF8);
	char *output = NewPtr(strlen+1);
	CFStringGetCString(input, output, strlen+1, kCFStringEncodingUTF8);
	return output;
}
开发者ID:dndump,项目名称:XboxLivePlugin,代码行数:10,代码来源:skype_messaging_carbon2.c


示例4: SetPtrSize

void *pgp_realloc(void *orig, long newLen)
{
#ifdef	PGP_MACINTOSH
	Ptr newSpace;
	long oldLen;
	
	if(orig)
		SetPtrSize((Ptr)orig, newLen);
	else
		orig=NewPtr(newLen);
	if(MemError())
	{
		if((newSpace = NewPtr(newLen)) != NULL)
		{
			oldLen=GetPtrSize((Ptr)orig);
			BlockMove(orig, newSpace, oldLen);
			DisposePtr((Ptr)orig);
			orig=newSpace;
		}
		else
			orig = NIL;
	}
	return orig;
#elif	PGP_WIN32
	void	*ptr = NULL;
#ifdef _DEBUG
	if (!HeapValidate(heapID, 0, NULL))
		DebugLog("validation failed before reallocating %d bytes at %p",
			newLen, ptr);
#endif	// _DEBUG

	ptr = HeapReAlloc(heapID, HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,
		ptr, newLen);

#ifdef _DEBUG
	if (!HeapValidate(heapID, 0, NULL))
		DebugLog("validation failed after reallocating %d bytes at %p",
			newLen, ptr);
#endif	// _DEBUG

	return ptr;
#endif	// PGP_WIN32
}
开发者ID:ysangkok,项目名称:pgpfone,代码行数:43,代码来源:PGPFoneUtils.cpp


示例5: _TIFFrealloc

void *
_TIFFrealloc(void* p, size_t s)
{
	Ptr n = p;

	SetPtrSize(p, s);
	if (MemError() && (n = NewPtr(s)) != NULL) {
		BlockMove(p, n, GetPtrSize(p));
		DisposePtr(p);
	}
	return (n);
}
开发者ID:edescourtis,项目名称:xv,代码行数:12,代码来源:tif_apple.c


示例6: _TIFFrealloc

tdata_t
_TIFFrealloc(tdata_t p, tsize_t s)
{
	Ptr n = p;

	SetPtrSize(p, (size_t) s);
	if (MemError() && (n = NewPtr((size_t) s)) != NULL) {
		BlockMove(p, n, GetPtrSize(p));
		DisposePtr(p);
	}
	return ((tdata_t) n);
}
开发者ID:OS2World,项目名称:LIB-PDFLib,代码行数:12,代码来源:tif_apple.c


示例7: NewPtr

void *pgp_malloc(long len)
{
	void	*ptr;

	//DebugLog("malloc:%ld\r",len);
#ifdef	PGP_MACINTOSH
	ptr = NewPtr(len);
#elif	PGP_WIN32
	ptr = HeapAlloc(heapID, HEAP_ZERO_MEMORY|HEAP_GENERATE_EXCEPTIONS, len);
#endif
	pgpAssert(IsntNull(ptr));
	return ptr;
}
开发者ID:ysangkok,项目名称:pgpfone,代码行数:13,代码来源:PGPFoneUtils.cpp


示例8: TclMacInitExitToShell

void 
TclMacInitExitToShell(
    int usePatch)	/* True if on 68k. */
{
    if (gExitToShellData == (ExitToShellDataPtr) NULL){
#if GENERATINGCFM
	gExitToShellData = (ExitToShellDataPtr)
	  NewPtr(sizeof(ExitToShellDataRec));
	gExitToShellData->a5 = SetCurrentA5();
	gExitToShellData->userProcs = (ExitToShellUPPList*) NULL;
#else
	ExitToShellUPP oldExitToShell, newExitToShellPatch;
	short exitToShellTrap;
	
	/*
	 * Initialize patch mechanism.
	 */
	 
	gExitToShellData = (ExitToShellDataPtr) NewPtr(sizeof(ExitToShellDataRec));
	gExitToShellData->a5 = SetCurrentA5();
	gExitToShellData->userProcs = (ExitToShellUPPList*) NULL;

	/*
	 * Save state needed to call origional ExitToShell routine.  Install
	 * the new ExitToShell code in it's place.
	 */
	if (usePatch) {
	    exitToShellTrap = _ExitToShell & 0x3ff;
	    newExitToShellPatch = NewExitToShellProc(ExitToShellPatchRoutine);
	    oldExitToShell = (ExitToShellUPP)
	      NGetTrapAddress(exitToShellTrap, ToolTrap);
	    NSetTrapAddress((UniversalProcPtr) newExitToShellPatch,
		    exitToShellTrap, ToolTrap);
	    gExitToShellData->oldProc = oldExitToShell;
	}
#endif
    }
}
开发者ID:gordonchaffee,项目名称:expectnt,代码行数:38,代码来源:tclMacExit.c


示例9: BetterAddElement

// moo is the element to insert the data after
Boolean BetterAddElement(Ptr dataPtr,Size dataSize,ElementHandle moo)
{
	// Moo now points to a Ptr to store the next element in. The Ptr is the address of the 'next'
	// field of the last element in the list.
	// Add a new ListElement to the list
	*moo=(ElementPtr)NewPtr(sizeof(ListElement));
	if (!*moo) // failed?
		return false;

	(*moo)->next=0L;
	(*moo)->data=0L;
	
	// Add the data to that element
	(*moo)->data=NewPtr(dataSize);
	if (!(*moo)->data) // failed?
	{
		DisposePtr((Ptr)*moo);
		*moo=0L;
		return false;
	}
	BlockMove(dataPtr,(*moo)->data,dataSize);
	return true;
}
开发者ID:MaddTheSane,项目名称:tntbasic,代码行数:24,代码来源:LinkedLists.c


示例10: PAS_decodeData

OSErr PAS_decodeData(PASEntry *entry, FSSpec *outFile, short inRefNum)
{
	OSErr 		err;	
	short		outRefNum;
	Ptr 		buffer;
	SInt32 		currentWrite = 	PAS_BUFFER_SIZE;
	SInt32		totalSize;
	
	
	buffer = NewPtr(currentWrite);
	
	
	err = FSpOpenDF(outFile, fsRdWrPerm, &outRefNum);
	if (err != noErr)	return err;
	
	
	err = SetFPos(inRefNum, fsFromStart, (*entry).entryOffset );
	if (err != noErr)	return err;
	
	err = SetFPos(outRefNum, fsFromStart, 0 );
	if (err != noErr)	return err;
	
	totalSize = (*entry).entryLength;
	
	while(totalSize > 0)
	{	
		currentWrite = PAS_BUFFER_SIZE;

		if (totalSize < currentWrite)
		{
			currentWrite = totalSize;
		}

		err	= FSRead( inRefNum, &currentWrite, buffer);
		if (err != noErr && err != eofErr)	return err;
	
		err = FSWrite(outRefNum, &currentWrite, buffer);
		if (err != noErr)	return err;
		
		totalSize = totalSize - currentWrite;

	}
	
	FSClose(outRefNum);
	
	DisposePtr(buffer);
	
	return noErr;

}
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:50,代码来源:su_pas.c


示例11: NewPtr

// This is the most overloaded routine I've seen in a long time.
void *realloc(
	void *pointer,
	size_t size)
{
	if ((pointer==NULL) && (size!=0))
	{
		return NewPtr(size);
	}
	
	if (size==0)
	{
		if (pointer) DisposePtr((Ptr)pointer);
		return NULL;
	}
	
	if (size==GetPtrSize((Ptr)pointer)) return pointer;
	
	SetPtrSize((Ptr)pointer, size);
	
	// SetPtrSize can fail if the pointer couldn't be expanded in place
	if (MemError())
	{
		Size old_size= GetPtrSize((Ptr)pointer);
		Ptr	realloced_pointer= NewPtr(size);

		// so we make a whole new one if possible
		if (MemError()) return NULL;
		
		// and copy the data into it.
		BlockMoveData(pointer, realloced_pointer, old_size > size ? size : old_size);
		// and then destroy the old pointer		
		DisposePtr((Ptr)pointer);
		
		return realloced_pointer;
	}
	return pointer;
}
开发者ID:DrItanium,项目名称:moo,代码行数:38,代码来源:macintosh_utilities.c


示例12: sqCopyDirectorysizetosize

int sqCopyDirectorysizetosize(char *srcNameIndex, int srcNameSize, char *dstNameIndex, int dstNameSize) {

	OSErr error;
	FSSpec	srcSpec,dstSpec,dstFolderSpec;
	char *pointer;
	const int desiredBufferSize = 64*1024;
    char name[256];

	memmove(name,srcNameIndex,srcNameSize);
	memmove(name+srcNameSize,":",1);
	FSpLocationFromFullPath(srcNameSize+1,name,&srcSpec);
	memmove(name,dstNameIndex,dstNameSize);
	memmove(name+dstNameSize,":",1);
	FSpLocationFromFullPath(dstNameSize+1,name,&dstFolderSpec);
	FSMakeFSSpecCompat(dstFolderSpec.vRefNum, dstFolderSpec.parID, "\p:", &dstSpec);

#if TARGET_API_MAC_CARBON
		pointer = NewPtr(desiredBufferSize);
#else
	    pointer = NewPtr(desiredBufferSize);
	    if (pointer == NULL) 
		    pointer = NewPtrSys(desiredBufferSize);
	    if (pointer == NULL) 
  			return false;
 #endif
    memmove(name,dstFolderSpec.name,sizeof(dstFolderSpec.name));
	error = FSpDirectoryCopy(&srcSpec,
						&dstSpec,
						(ConstStr255Param) &name,
						pointer,
						desiredBufferSize,
						false,
						&handleDupError);

	DisposePtr((void *)pointer);
	return error;
} 
开发者ID:Geal,项目名称:Squeak-VM,代码行数:37,代码来源:sqMacFileCopy.c


示例13: MinimalSGSettingsDialog

//  SGSettingsDialog with the "Compression" panel removed
static OSErr MinimalSGSettingsDialog(SeqGrabComponent seqGrab,
                                     SGChannel sgchanVideo, WindowPtr gMonitor)
{
        OSErr err;
        Component *panelListPtr = NULL;
        UInt8 numberOfPanels = 0;

        ComponentDescription cd = { SeqGrabPanelType, VideoMediaType, 0, 0, 0 };
        Component c = 0;
        Component *cPtr = NULL;

        numberOfPanels = CountComponents(&cd);
        panelListPtr =
            (Component *) NewPtr(sizeof(Component) * (numberOfPanels + 1));

        cPtr = panelListPtr;
        numberOfPanels = 0;
        CFStringRef compressionCFSTR = CFSTR("Compression");
        do {
                ComponentDescription compInfo;
                c = FindNextComponent(c, &cd);
                if (c) {
                        Handle hName = NewHandle(0);
                        GetComponentInfo(c, &compInfo, hName, NULL, NULL);
                        CFStringRef nameCFSTR =
                            CFStringCreateWithPascalString(kCFAllocatorDefault,
                                                           (unsigned char
                                                            *)(*hName),
                                                           kCFStringEncodingASCII);
                        if (CFStringCompare
                            (nameCFSTR, compressionCFSTR,
                             kCFCompareCaseInsensitive) != kCFCompareEqualTo) {
                                *cPtr++ = c;
                                numberOfPanels++;
                        }
                        DisposeHandle(hName);
                }
        } while (c);

        if ((err =
             SGSettingsDialog(seqGrab, sgchanVideo, numberOfPanels,
                              panelListPtr, seqGrabSettingsPreviewOnly,
                              (SGModalFilterUPP)
                              NewSGModalFilterUPP(SeqGrabberModalFilterProc),
                              (long)gMonitor))) {
                return err;
        }
        return 0;
}
开发者ID:MattHung,项目名称:sage-graphics,代码行数:50,代码来源:quicktime.c


示例14: NATCPwrite

/* pass a buffer to tcp connection for writing
 *  dispose of -1 = copy data
 */
short NATCPwrite(na_tcp i, Ptr data, long len, short dispose)
{
	tcpinfo *tcp = (*tcpstate)->tcpbufs[i];
	rdsEntry *rds = NULL;
	tcpwb *wb;
	long totallen = 0;
	int j;
	
	if (tcp == NULL || tcp->lclose > 0 || tcp->rclose == 3) {
		return (NATCP_nocon);
	}
	wb = tcp->wb + tcp->wbnum;
	if (wb->rused == RDS) wb = tcp->wb + (1 - tcp->wbnum);
	if (wb->rused == -1 || wb->rused == RDS) return (NATCP_notcpbuf);
	for (j = 0; j < wb->rused; ++j) {
		totallen += wb->rds[j].length;
	}
	if (totallen + len >= 65535) return (NATCP_notcpbuf);
	rds = wb->rds + wb->rused;
	rds->length = len;
	rds->ptr = data;
	rds[1].length = 0;
	if (dispose < 0) {
		if (len < tcp->wbsize - wb->wused) {
			/* if data short enough, use small internal buffer */
			rds->ptr = wb->buf + wb->wused;
			wb->wused += len;
			dispose = 0;
			/* If adjacent to last rds, attach to it */
			if (wb->rused && rds[-1].ptr + rds[-1].length == rds->ptr) {
				--wb->rused;
				rds[-1].length += len;
				rds->length = 0;
			}
		} else {
			rds->ptr = NewPtr(len);
			if (!rds->ptr) return (NATCP_nomem);
			dispose = 1;
		}
		memcpy(rds->ptr, data, len);
	}
	wb->fflag[wb->rused++] = dispose;
	if (tcp->push && tcp->state == TCP_READY) {
		(void) beginwrite(tcp);
	}
	
	return (NATCP_data);
}
开发者ID:ChristianeDufresne,项目名称:GUD,代码行数:51,代码来源:macntcp.c


示例15: begin_track_buffering_for_write

PRIVATE OSErr
begin_track_buffering_for_write (void)
{
  OSErr retval;

  track_bufp = NewPtr (N_TRACK_BYTES);
  if (track_bufp)
    {
      retval = noErr;
      offset = 0;
      length = 0;
    }
  else
    retval = MemErr;
  return retval;
}
开发者ID:LarBob,项目名称:executor,代码行数:16,代码来源:diskinit.c


示例16: CopyGammaTable

static Ptr CopyGammaTable (GammaTblPtr pTableGammaIn)
{
	GammaTblPtr		pTableGammaOut = NULL;
	short			tableSize, dataWidth;

	if (pTableGammaIn)												
	{
		dataWidth = (pTableGammaIn->gDataWidth + 7) / 8;			
		tableSize = sizeof (GammaTbl) + pTableGammaIn->gFormulaSize +
					(pTableGammaIn->gChanCnt * pTableGammaIn->gDataCnt * dataWidth);
		pTableGammaOut = (GammaTblPtr) NewPtr (tableSize);			
		if (pTableGammaOut)											
			BlockMove( (Ptr)pTableGammaIn, (Ptr)pTableGammaOut, tableSize);	
	}
	return (Ptr)pTableGammaOut;										
}
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:16,代码来源:SDL_macwm.c


示例17: CopyGammaTable

static Ptr CopyGammaTable (GammaTblPtr pTableGammaIn)
{
	GammaTblPtr		pTableGammaOut = NULL;
	short			tableSize, dataWidth;

	if (pTableGammaIn)												/* if there is a table to copy  */
	{
		dataWidth = (pTableGammaIn->gDataWidth + 7) / 8;			/* number of bytes per entry */
		tableSize = sizeof (GammaTbl) + pTableGammaIn->gFormulaSize +
					(pTableGammaIn->gChanCnt * pTableGammaIn->gDataCnt * dataWidth);
		pTableGammaOut = (GammaTblPtr) NewPtr (tableSize);			/* allocate new table */
		if (pTableGammaOut)											
			BlockMove( (Ptr)pTableGammaIn, (Ptr)pTableGammaOut, tableSize);	/* move everything */
	}
	return (Ptr)pTableGammaOut;										/* return whatever we allocated, could be NULL */
}
开发者ID:ahpho,项目名称:wowmapviewer,代码行数:16,代码来源:SDL_macwm.c


示例18: FetchParamAnySize

OSErr FetchParamAnySize(AEKeyword plop,AppleEvent *appIn,Ptr *dest,DescType theType)
{
	OSErr	err;
	Size	size;
	DescType	actualType;

	err=AESizeOfParam(appIn,plop, &actualType, &size);
	if (err)
		return err;
	
	*dest=NewPtr(size);
	
	err=AEGetParamPtr(appIn, plop, theType, &actualType, *dest, size, &size);

	return err;
}
开发者ID:MaddTheSane,项目名称:tntbasic,代码行数:16,代码来源:AppleEvents.cpp


示例19: NewMachOFunctionPointer

//
//	This function allocates a block of CFM glue code which contains the instructions to call CFM routines
//
static void* NewMachOFunctionPointer(void* cfmfp)
{
#if TARGET_RT_MAC_CFM
    static UInt32 CFM_glue[6] = {0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004, 0x7C0903A6, 0x4E800420};
    UInt32	*mfp = (UInt32*) NewPtr(sizeof(CFM_glue));		//	Must later dispose of allocated memory
    if (mfp) {
	    BlockMoveData(CFM_glue, mfp, sizeof(CFM_glue));
	    mfp[0] |= ((UInt32)cfmfp >> 16);
	    mfp[1] |= ((UInt32)cfmfp & 0xFFFF);
	    MakeDataExecutable(mfp, sizeof(CFM_glue));
	}
	return mfp;
#elif TARGET_RT_MAC_MACHO
    return cfmfp;
#endif
}
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:19,代码来源:MRJSession.cpp


示例20: MaxBlock

void *my_malloc (int n)
{
	int i = MaxBlock ();
	void *x;

	if (n >= i) {
		printf ("Error: malloc = %d, maxblock = %d\n", n, i);
		exit (-1);
	}

	if ((x = (void *)NewPtr(n)) == NULL) {
		printf ("Error: %d\n", MemError());
		exit (-1);
	}

	return x;
}
开发者ID:SimonKagstrom,项目名称:sarien-j2me,代码行数:17,代码来源:library.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ NewString函数代码示例发布时间:2022-05-30
下一篇:
C++ NewObject函数代码示例发布时间: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