?? jpeg_memalloc.c
字號:
/*****************************************************************************
Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved. This software is
proprietary and confidential to Analog Devices, Inc. and its licensors.
******************************************************************************
$RCSfile: JPEG_MemAlloc.c,v $
$Revision: 1.1 $
$Date: 2006/07/17 07:44:02 $
Project: JPEG IMAGE CODEC
Title: JPEG Memory Management
Author(s): D.G
Revised by:
Description:
Module for Memory allocation and de-allocation.
References:
******************************************************************************
Tab Setting: 4
Target Processor: Blackfin
Target Tools Revision: ccblkfn C/C++ compiler 6.3.0.0
easmblkfn BlackFin assembler 2.2.4.1
elfar ELF Librarian/Archive Utility 4.4.1.2
linker Linker 2.8.8.2
******************************************************************************
Modification History:
====================
$Log: JPEG_MemAlloc.c,v $
Revision 1.1 2006/07/17 07:44:02 bmk
JPEG-MJPEG User access files
******************************************************************************/
#include <stdlib.h> // heap_malloc()
#include "JPEG_memalloc.h" // User defined typedefs
extern size_t ldf_fast_heap_length;
/****************************************************************************
* Function Declarations *
****************************************************************************/
/*
*******************************************************************************
** Function: JPEG_MemAlloc_NEW
**
** Description: This function must be used to allocate memory. When
** it is not required any more, the user must call JPEG_MemAlloc_DELETE to
** release the data buffer memory. NULL is returned if there is not enough
** memory available. Please note that all memory allocated by this
** function must be aligned to 4 byte boundaries (note that malloc returns
** 8 byte aligned memory).
**
** Arguments:
**
** N_element [IN] The number of elements that the requested area of memory
** will store.
** size [IN] The number of bytes occupied by each element.
** attr [IN] One of MEM_TYPE_DATA, MEM_TYPE_TABLE and MEM_TYPE_OBJECT
** that identifies the type of memory being allocated. Note
** that these parameters are pre-defined. The user cannot
** modify them.
**
** Outputs:
**
** Return value: Pointer to a memory object handle that contains a pointer
** to the (nobj x size) bytes uninitialised memory space.
** NULL upon failure.
*******************************************************************************
*/
MemObjHandle *JPEG_MemAlloc_NEW (int N_element, int size, Mem_type attr)
{
MemObjHandle *MemObj = NULL;
int length = N_element * size;
int idx;
int userid;
// userid corresponds to the which heap is used as defined in heaptab.s / jpeg_libtest.ldf
// 0 = regular heap, slow (L3) memory
// 1 = user defined heap, standard (L2) memory (using L3 for the BF533)
// 2 = user defined heap, fast (L1) memory
MemObj = (MemObjHandle *)heap_malloc(1, sizeof(MemObjHandle));
if (MemObj == NULL)
return NULL;
switch (attr)
{
case MEM_TYPE_DATA:
{
// if (length > 2048)
if ((unsigned int)length > (unsigned int)ldf_fast_heap_length/2)
{
userid = 1;
break;
}
else
{
userid = 2;
break;
}
}
case MEM_TYPE_TABLE:
userid = 2; break;
case MEM_TYPE_OBJECT:
userid = 2; break;
default:
return NULL;
}
// for loop allocates slower memory if fast memory is unavailable
// this requires the userid's in heaptab.s to be ordered from slow to fast
for (userid; userid >= 0; userid--)
{
idx = heap_lookup(userid);
MemObj->MemoryAllocated = heap_malloc(idx, length);
if (MemObj->MemoryAllocated != NULL)
return MemObj;
}
// memory not successfully allocated
// deallocate object
heap_free(0, MemObj); // idx is ignored by heap free
return NULL;
}
/*
*******************************************************************************
** Function: JPEG_MemAlloc_DELETE
**
** Description: This function frees the data buffer memory object that was
** allocated after calling the function JPEG_MemAlloc_NEW.
**
** Arguments:
**
** mem_obj [IN] Handle to memory object instance. If NULL is passed,
** function does nothing.
**
** Outputs:
**
** Return value: None.
*******************************************************************************
*/
void JPEG_MemAlloc_DELETE (MemObjHandle *mem_obj)
{
if(mem_obj==NULL)
{
return;
}
// delete memory block allocated
heap_free(0, mem_obj->MemoryAllocated); // idx is ignored by heap free
// delete memory object
heap_free(0, mem_obj); // idx is ignored by heap free
}
/*
*******************************************************************************
** Function: JPEG_MemAlloc_ADDRESS
**
** Description: This function must return a pointer to the data buffer memory
** that was allocated within the memory object mem_obj.
**
** Arguments:
**
** mem_obj [IN] Handle to memory object instance.
**
** Outputs:
**
** Return value: Pointer to an uninitialised memory space containing
** (N_element x size) bytes that was allocated by
** JPEG_MemAlloc_NEW.
*******************************************************************************
*/
void *JPEG_MemAlloc_ADDRESS (MemObjHandle *mem_obj)
{
return mem_obj->MemoryAllocated;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -