Beispiel #1
0
/**
 * Changes size of preallocated space for memory object "pObject"
 * to the new size specified by "constSize".
 *
 * If the new size is larger than the old size, the old contents
 * is not changed. Additionally space is added at the the end of
 * "pObject". The new allocated space is not initialized
 * to any special value.
 * If the new size is smaller than the old size, the unused space
 * is discarded.
 *
 * If "pObject" is a NULL pointer, this function behaves just like
 * smlLibMalloc().
 * If "pObject" does not point to a previously allocated memory area,
 * the behavior is undefined.
 * If "constSize" is 0, a NULL pointer is returned and the space
 * which "pObject" points to is freed up.
 *
 * Returns a pointer to the first byte of the resized object.
 * If no new memory could be allocated, a NULL Pointer is returned
 * without changing the memory object "pObject" (Nothing happens to the content).
 *
 * @param pObject (IN/OUT)
 *        memory object, which size should be changed
 * @param constSize (IN)
 *        new size the memory object shall use
 * @return void pointer to memory object, which size has been be changed\n
 *         NULL, if not successfull or if constSize==0
 */
SML_API void *smlLibRealloc(void *pObject, MemSize_t constSize)
{
#ifdef __PALM_OS__
  VoidPtr_t _new_object;
  MemSize_t   _old_size;

    // It's a malloc!
    if (pObject == NULL)
        return smlLibMalloc(constSize);

    _old_size = MemPtrSize(pObject);
    if (constSize <= _old_size) {
        // make it smaller
        MemPtrResize(pObject, constSize);
        _new_object = pObject;
    } else {
        // maker it larger (we need to allocate new memory somewhere else)
        _new_object = smlLibMalloc(constSize);
        if (_new_object != NULL) {
            smlLibMemmove(_new_object, pObject, _old_size);
            smlLibFree(pObject);
        }
    }

  return _new_object;
#else
  // %%% luz 2002-10-02
  #ifdef MEMORY_PROFILING
  return sysync_realloc(pObject, constSize);
  #else
  return realloc(pObject, constSize);
  #endif
#endif
}
Beispiel #2
0
/**
 * FUNCTION: smlLibRealloc
 *
 * Changes size of preallocated space for memory object "pObject"
 * to the new size specified by "constSize".
 *
 * If the new size is larger than the old size, the old contents 
 * is not changed. Additionally space is added at the the end of 
 * "pObject". The new allocated space is not initialized 
 * to any special value.
 * If the new size is smaller than the old size, the unused space
 * is discarded.
 *
 * If "pObject" is a NULL pointer, this function behaves just like 
 * smlLibMalloc().
 * If "pObject" does not point to a previously allocated memory area, 
 * the behavior is undefined.
 * If "constSize" is 0, a NULL pointer is returned and the space 
 * which "pObject" points to is freed up.
 *
 * Returns a pointer to the first byte of the resized object.
 * If no new memory could be allocated, a NULL Pointer is returned 
 * without changing the memory object "pObject" (Nothing happens to the content).
 *
 * IN/OUT           void *pObject,      memory object, which size should be changed
 * IN:              MemSize_t constSize new size the memory object shall use
 * RETURN:          void*               Pointer to memory object, which size has been
 *                                      be changed
 *                                      NULL, if not successfull or
 *                                            if constSize==0
 */
SML_API void *smlLibRealloc(void *pObject, MemSize_t constSize)
{
#ifdef __PALM_OS__
	VoidPtr_t	_new_object;
	MemSize_t 	_old_size;    
  
  	// It's a malloc!
  	if (pObject == NULL)
    		return smlLibMalloc(constSize);
    
  	_old_size = MemPtrSize(pObject); 
  	if (constSize <= _old_size) {
     		// make it smaller
     		MemPtrResize(pObject, constSize);
     		_new_object = pObject;
  	} else {
     		// maker it larger (we need to allocate new memory somewhere else)
     		_new_object = smlLibMalloc(constSize);
     		if (_new_object != NULL) {
        		smlLibMemmove(_new_object, pObject, _old_size);
        		smlLibFree(pObject);
     		}
  	}           

	return _new_object;
#else
  return DmReallocMem(pObject, (UINT32)constSize);
	
#endif
}
Beispiel #3
0
void* PrvRealloc(void* p, UInt32 newSize)
{
    if (0 == newSize)
    {
        if (NULL != p)
            MemPtrFree(p);
        return NULL;
    }
    newSize = PrvBlockSize(newSize);
    if (NULL == p)
        return MemGluePtrNew(newSize);

    UInt32 size = MemPtrSize(p);
    if (newSize <= size)
        return p;

    Err err = MemPtrResize(p, newSize);
    if (errNone == err)
        return p;

    void* np = MemGluePtrNew(newSize);
    if (NULL != np)
        MemMove(np, p, size);

    MemPtrFree(p);
    return np;
}
XPTEXP1 void * XPTAPI XPTEXP2 xppRealloc(void *ptr, size_t size) {
   Err rc;
   UInt32 currentSize;
   void *newMem;

   /* If original pointer is null, act like a normal malloc                */
   if (!ptr) return MemPtrNew(size);

   /* Try resizing original area.  This will always work if the new area   */
   /* is smaller.  It may or may not work if growing the area.             */
   rc = MemPtrResize(ptr, size);
   if (!rc) return ptr;             /* It worked.  Return same pointer.    */

   /* Resizing didn't work.  Allocate a new, larger, area, and copy the    */
   /* previous data from the old area.                                     */
   newMem = MemPtrNew(size);
   if (!newMem) return newMem;      /* Pass error to caller                */

   /* The original size must be smaller than the new size                  */
   currentSize = MemPtrSize(ptr);
   MemMove(newMem, ptr, currentSize);

   /* Release the old area.                                                */
   MemPtrFree(ptr);

   return newMem;
}
MemPtr realloc(MemPtr oldP, UInt32 size) {
    MemPtr newP;

    if (oldP != NULL)
        if (MemPtrResize(oldP, size) == 0)
            return oldP;

    newP = malloc(size);	// was MemPtrNew

    if (oldP!=NULL) {
        MemMove(newP,oldP,MemPtrSize(oldP));
        MemPtrFree(oldP);
    }

    return newP;
}
Beispiel #6
0
int memMgrChunkResize(void *ptr, unsigned long size)
{
    Err             result  = systemErrNone;
    UInt32          ptrSize = 0;
    
    if (!ptr || !size)
        return memoryErrInvalidParam;
    
    ptrSize = memMgrChunkSize(ptr);
        
    result = MemPtrResize(ptr, size);
    
    if (result == systemErrNone) {
        memMgrIncramentSizeCount(ptrSize, true);
        memMgrIncramentSizeCount(size, false);
    }
    
    return result;
}
Beispiel #7
0
void* realloc__(void* p, size_t size, const char* file, int line)
{
    if (NULL != p && 0 == size)
    {
        free__(p);
        return NULL;
    }
    if (NULL == p)
        return malloc__(size, file, line);

#ifdef _PALM_OS

    if (errNone == MemPtrResize(p, size))
        return p;

    void* np = malloc__(size, file, line);
    if (NULL == np)
        return NULL;

    MemMove(np, p, MemPtrSize(p));
    free__(p);

#elif defined(_WIN32_WCE)

    void* np = realloc(p, size);
#ifndef NDEBUG    
    if (np != p)
    {
        logAllocation(p, 0, true, __FILE__, __LINE__);
        if (NULL != np)
            logAllocation(np, size, false, __FILE__, __LINE__);
    }
#endif    

#endif

    return np;
}
Beispiel #8
0
/***********************************************************************
 *
 * FUNCTION:    FntDefineFont
 *
 * DESCRIPTION: Define a font.  Only an app font may be defined.  The
 * application is responsible for freeing or releasing the font when
 * the application quits.
 *
 * PARAMETERS:  fontID - id of the font to define.  Should be a app defined
 * 							 font only.
 *					 fontP - Pointer to font to use.
 *
 * RETURNED:    memErrNotEnoughSpace - if it isn't able to allocate
 *						space for the new font in the font table.
 *					 0 - if no error
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			roger	 9/26/97	Initial Revision
 *			SCL	12/10/97	Rewrote to support new (separate) app font table
 *			roger	11/ 9/98	Fixed MemMove reading past end of source.
 *			gavin	11/18/98	set UINumAppFonts to count, not index
 *			SCL	11/25/98	Fixed MemMove to copy exact size of old table
 *			vivek 06/07/00 Added support for hierarchical application fonts
 *
 ***********************************************************************/
Err FntDefineFont (FontID fontID, FontPtr fontP)
{
	UInt32			reqSize;
	FontTablePtr	tableP;
	FontTablePtr	newTableP;
	Err				err;
	Int16				appFontIndex;
	Int16				fontIndex;
	Int16				numAppFonts;
	Boolean			isSubFont;

	ErrNonFatalDisplayIf (!FntIsAppDefined(fontID), "App defined fonts only");
	// KEY POINT:  "...Index" is a zero-based array index, whereas
	// "...Num...Fonts" is a one-based number of fonts.
	// Thus, appFontIndex is the array index into which fontP will be installed.
	// The font table must be large enough to support this new font index.
	
	isSubFont = (fontP->fontType & fntAppSubFontMask) ? true : false;
	
	if (isSubFont)
		{
			numAppFonts = MemPtrSize(GAppSubFontListPtr) / sizeof(FontPtr);		
			tableP = GAppSubFontListPtr;
		}
	else
		{
			tableP = UIAppFontTablePtr;
			numAppFonts = UINumAppFonts;
		}
	
	appFontIndex = (FontID) (fontID - fntAppFontCustomBase);
	
		
	// See if there's room in the app font table for this font
	if (appFontIndex >= numAppFonts) 
		{
		// if not, try to resize the table (new size is appFontIndex+1 entries)
		reqSize = (appFontIndex+1) * sizeof(FontPtr);
		err = MemPtrResize(tableP, reqSize);
		
		// If we couldn't resize it, try and reallocate it
		if (err) 
			{
			newTableP = MemPtrNew(reqSize);
			if (!newTableP) return memErrNotEnoughSpace;
			
			// Copy old table (numFonts entries) into new table
			MemMove(newTableP, tableP, numAppFonts * sizeof(FontPtr));
			MemPtrSetOwner(newTableP, 0);

			// Change global to point to new table, and free the old one
			if (isSubFont)
				GAppSubFontListPtr = newTableP;
			else
				UIAppFontTablePtr = newTableP;
			
			MemPtrFree(tableP);
			tableP = newTableP;
			}

		// Zero out (only) the newly added slots in the table
		for (fontIndex = numAppFonts; fontIndex <= appFontIndex; fontIndex++) 
			{
			tableP[fontIndex] = NULL;
			}
		
		// Save the new table size
		if (!isSubFont)
			UINumAppFonts = appFontIndex+1;
		}

	tableP[appFontIndex] = fontP;
		
	return 0;
}