2 ** Copyright 2003-2010, VisualOn, Inc.
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
8 ** http://www.apache.org/licenses/LICENSE-2.0
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
17 /*******************************************************************************
20 Content: Memory alloc alignments functions
22 *******************************************************************************/
25 #include "mem_align.h"
27 /*****************************************************************************
29 * function name: mem_malloc
30 * description: malloc the alignments memory
31 * returns: the point of the memory
33 **********************************************************************************/
35 mem_malloc(VO_MEM_OPERATOR *pMemop, unsigned int size, unsigned char alignment, unsigned int CodecID)
38 unsigned char *mem_ptr;
44 MemInfo.Size = size + 1;
45 ret = pMemop->Alloc(CodecID, &MemInfo);
48 mem_ptr = (unsigned char *)MemInfo.VBuffer;
50 pMemop->Set(CodecID, mem_ptr, 0, size + 1);
52 *mem_ptr = (unsigned char)1;
54 return ((void *)(mem_ptr+1));
59 MemInfo.Size = size + alignment;
60 ret = pMemop->Alloc(CodecID, &MemInfo);
64 tmp = (unsigned char *)MemInfo.VBuffer;
66 pMemop->Set(CodecID, tmp, 0, size + alignment);
69 (unsigned char *) ((unsigned int) (tmp + alignment - 1) &
70 (~((unsigned int) (alignment - 1))));
75 *(mem_ptr - 1) = (unsigned char) (mem_ptr - tmp);
77 return ((void *)mem_ptr);
84 /*****************************************************************************
86 * function name: mem_free
87 * description: free the memory
89 *******************************************************************************/
91 mem_free(VO_MEM_OPERATOR *pMemop, void *mem_ptr, unsigned int CodecID)
103 pMemop->Free(CodecID, ptr);