[svn] / trunk / xvidcore / src / utils / mem_align.c Repository:
ViewVC logotype

View of /trunk/xvidcore/src/utils/mem_align.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (download) (annotate)
Wed Mar 20 00:28:02 2002 UTC (19 years, 8 months ago) by Isibaar
File size: 696 byte(s)
xvid_malloc/xvid_free
#include <stdlib.h>
#include <stdio.h>
#include "mem_align.h"

void *xvid_malloc(size_t size, uint8_t alignment)
{
  uint8_t *mem_ptr;
  
  if(alignment == 0)
  {
	  if((mem_ptr = (uint8_t *) malloc(size + 1)) != NULL) {
		*mem_ptr = 0;
		return (void *) mem_ptr++;
	  }
  }
  else
  {
	  uint8_t *tmp;
	
	  if((tmp = (uint8_t *) malloc(size + alignment)) != NULL) {
		mem_ptr = (uint8_t *) (((uint32_t) tmp / alignment) * alignment + alignment);
		*(mem_ptr - 1) = (alignment - 1) - ((uint32_t) tmp % alignment);
		return (void *) mem_ptr;
	  }
  }

  return NULL;
}

void xvid_free(void *mem_ptr)
{
  uint8_t *tmp;

  tmp = (uint8_t *) mem_ptr - 1;
  mem_ptr  = tmp - *tmp;

  free(mem_ptr);
}

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4