MemoryDealer.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (C) 2007 The Android Open Source Project
  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 express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef ANDROID_MEMORY_DEALER_H
  17. #define ANDROID_MEMORY_DEALER_H
  18. #include <stdint.h>
  19. #include <sys/types.h>
  20. #include <binder/IMemory.h>
  21. #include <binder/MemoryHeapBase.h>
  22. namespace android {
  23. // ----------------------------------------------------------------------------
  24. class SimpleBestFitAllocator;
  25. // ----------------------------------------------------------------------------
  26. class MemoryDealer : public RefBase
  27. {
  28. public:
  29. MemoryDealer(size_t size, const char* name = 0,
  30. uint32_t flags = 0 /* or bits such as MemoryHeapBase::READ_ONLY */ );
  31. virtual sp<IMemory> allocate(size_t size);
  32. virtual void deallocate(size_t offset);
  33. virtual void dump(const char* what) const;
  34. sp<IMemoryHeap> getMemoryHeap() const { return heap(); }
  35. protected:
  36. virtual ~MemoryDealer();
  37. private:
  38. const sp<IMemoryHeap>& heap() const;
  39. SimpleBestFitAllocator* allocator() const;
  40. sp<IMemoryHeap> mHeap;
  41. SimpleBestFitAllocator* mAllocator;
  42. };
  43. // ----------------------------------------------------------------------------
  44. }; // namespace android
  45. #endif // ANDROID_MEMORY_DEALER_H