1 |
/***************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Aligned memory allocator - |
* - Aligned Memory Allocator - |
5 |
* |
* |
6 |
* This program is an implementation of a part of one or more MPEG-4 |
* Copyright(C) 2002-2003 Edouard Gomez <ed.gomez@free.fr> |
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
|
|
* to use this software module in hardware or software products are |
|
|
* advised that its use may infringe existing patents or copyrights, and |
|
|
* any such use would be at such party's own risk. The original |
|
|
* developer of this software module and his/her company, and subsequent |
|
|
* editors and their companies, will have no liability for use of this |
|
|
* software or modifications or derivatives thereof. |
|
7 |
* |
* |
8 |
* This program is free software ; you can redistribute it and/or modify |
* This program is free software ; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
19 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* |
* |
|
****************************************************************************/ |
|
|
/***************************************************************************** |
|
|
* |
|
|
* History |
|
|
* |
|
|
* - Thu Jun 13 23:50:07 2002 Added legal header |
|
|
* |
|
22 |
* $Id$ |
* $Id$ |
23 |
* |
* |
24 |
****************************************************************************/ |
****************************************************************************/ |
25 |
|
|
|
|
|
26 |
#include <stdlib.h> |
#include <stdlib.h> |
27 |
#include <stdio.h> |
#include <stdio.h> |
28 |
#include "mem_align.h" |
#include "mem_align.h" |
56 |
if ((mem_ptr = (uint8_t *) malloc(size + 1)) != NULL) { |
if ((mem_ptr = (uint8_t *) malloc(size + 1)) != NULL) { |
57 |
|
|
58 |
/* Store (mem_ptr - "real allocated memory") in *(mem_ptr-1) */ |
/* Store (mem_ptr - "real allocated memory") in *(mem_ptr-1) */ |
59 |
*mem_ptr = 0; |
*mem_ptr = 1; |
60 |
|
|
61 |
/* Return the mem_ptr pointer */ |
/* Return the mem_ptr pointer */ |
62 |
return (void *) mem_ptr++; |
return (void *)(mem_ptr+1); |
63 |
|
|
64 |
} |
} |
65 |
|
|
75 |
|
|
76 |
/* Align the tmp pointer */ |
/* Align the tmp pointer */ |
77 |
mem_ptr = |
mem_ptr = |
78 |
(uint8_t *) ((uint32_t) (tmp + alignment - 1) & |
(uint8_t *) ((ptr_t) (tmp + alignment - 1) & |
79 |
(~(uint32_t) (alignment - 1))); |
(~(ptr_t) (alignment - 1))); |
80 |
|
|
81 |
/* |
/* |
82 |
* Special case where malloc have already satisfied the alignment |
* Special case where malloc have already satisfied the alignment |