本文整理汇总了C++中NewPtr函数的典型用法代码示例。如果您正苦于以下问题:C++ NewPtr函数的具体用法?C++ NewPtr怎么用?C++ NewPtr使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewPtr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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
}
示例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);
}
示例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);
}
示例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;
}
示例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
}
}
示例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;
}
示例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, ¤tWrite, buffer);
if (err != noErr && err != eofErr) return err;
err = FSWrite(outRefNum, ¤tWrite, buffer);
if (err != noErr) return err;
totalSize = totalSize - currentWrite;
}
FSClose(outRefNum);
DisposePtr(buffer);
return noErr;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}