1/*
2 * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12
13
14#ifndef PX_FOUNDATION_PX_BROADCASTING_ALLOCATOR_H
15#define PX_FOUNDATION_PX_BROADCASTING_ALLOCATOR_H
16
17#include "foundation/PxAllocatorCallback.h"
18
19/** \addtogroup foundation
20 @{
21*/
22#ifndef PX_DOXYGEN
23namespace physx
24{
25#endif
26
27 /**
28 \brief Abstract listener class that listens to allocation and deallocation events from the
29 foundation memory system.
30
31 <b>Threading:</b> All methods of this class should be thread safe as it can be called from the user thread
32 or the physics processing thread(s).
33 */
34 class PxAllocationListener
35 {
36 protected:
37 virtual ~PxAllocationListener(){}
38
39 public:
40 /**
41 \brief callback when memory is allocated.
42 \param size Size of the allocation in bytes.
43 \param typeName Type this data is being allocated for.
44 \param filename File the allocation came from.
45 \param line the allocation came from.
46 \param allocatedMemory memory that will be returned from the allocation.
47 */
48 virtual void onAllocation( size_t size, const char* typeName, const char* filename, int line, void* allocatedMemory ) = 0;
49
50 /**
51 \brief callback when memory is deallocated.
52 \param allocatedMemory memory just before allocation.
53 */
54 virtual void onDeallocation( void* allocatedMemory ) = 0;
55 };
56
57 /**
58 \brief Abstract base class for an application defined memory allocator that allows an external listener
59 to audit the memory allocations.
60
61 <b>Threading:</b> Register/deregister are *not* threadsafe!!!
62 You need to be sure multiple threads are using this allocator when you are adding
63 new listeners.
64 */
65 class PxBroadcastingAllocator : public PxAllocatorCallback
66 {
67 protected:
68 virtual ~PxBroadcastingAllocator(){}
69
70 public:
71 /**
72 \brief Register an allocation listener. This object will be notified whenever an
73 allocation happens.
74
75 <b>Threading:</b>Not threadsafe if you are allocating and deallocating in another
76 thread using this allocator.
77 */
78 virtual void registerAllocationListener( PxAllocationListener& inListener ) = 0;
79 /**
80 \brief Deregister an allocation listener. This object will no longer receive
81 notifications upon allocation.
82
83 <b>Threading:</b>Not threadsafe if you are allocating and deallocating in another
84 thread using this allocator.
85 */
86 virtual void deregisterAllocationListener( PxAllocationListener& inListener ) = 0;
87 };
88
89#ifndef PX_DOXYGEN
90} // namespace physx
91#endif
92
93 /** @} */
94#endif // PX_FOUNDATION_PX_BROADCASTING_ALLOCATOR_H
95