1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 19 #ifndef SDP_MEMORY_H 20 #define SDP_MEMORY_H 21 22 #include "oscl_mem.h" 23 24 #include "oscl_base_alloc.h" 25 26 typedef OsclMemAllocator SDPParserAlloc; 27 28 class SDPMemory 29 { 30 public: 31 SDPMemory() {}; 32 ~SDPMemory() {}; 33 template <class T> T* alloc(uint32 size, T* temp) 34 { 35 T* ptr = (T*)oscl_malloc(size); 36 return ptr; 37 }; 38 template <class T> void dealloc(T* p) 39 { 40 oscl_free(p); 41 }; 42 }; 43 44 template <class T> class SDPAllocDestructDealloc: public OsclDestructDealloc 45 { 46 public: 47 virtual ~SDPAllocDestructDealloc() {} 48 49 T* allocate(uint32 size) 50 { 51 SDPParserAlloc alloc; 52 T* ptr = OSCL_PLACEMENT_NEW(alloc.ALLOCATE(size), T()); 53 return ptr; 54 } 55 56 virtual void destruct_and_dealloc(OsclAny* ptr) 57 { 58 T* tptr ; 59 tptr = reinterpret_cast<T*>(ptr); 60 tptr->~T(); 61 SDPParserAlloc alloc; 62 alloc.deallocate(ptr); 63 } 64 }; 65 66 #endif 67 68 69