Successfully replaced the ptrace-based allocation gathering with LD_PRELOAD.
[aesalon.git] / gui / src / ActiveSessionMemoryStorage.h
blobd7edbb4109217a8501fee4f3ef1df9ba887662db
1 #ifndef AESALON_GUI_ACTIVE_SESSION_MEMORY_STORAGE_H
2 #define AESALON_GUI_ACTIVE_SESSION_MEMORY_STORAGE_H
4 #include <QtGlobal>
5 #include <QMap>
7 class ActiveSessionMemoryBlock;
8 class ActiveSessionMemorySnapshot;
10 /** The type used for storing data offsets. This MUST be a signed type, as
11 negative offsets in Snapshots indicate item removals. */
12 typedef qint64 StorageOffset;
14 class ActiveSessionMemoryStorage {
15 public:
16 enum allocation_mode_e {
17 ALLOC_MODE_1M,
18 ALLOC_MODE_DOUBLE
20 enum data_type_e {
21 INVALID_DATA,
22 BLOCK_DATA,
23 SNAPSHOT_DATA
25 private:
26 quint8 *data;
27 StorageOffset data_size;
28 StorageOffset unused_offset;
30 allocation_mode_e allocation_mode;
32 /** A QMap is used to store the type of each StorageOffset.
33 QMap::operator[] is O(log n) for accessing, so it should be fast enough.
35 QMap<StorageOffset, data_type_e> data_types;
37 /** Reserves more memory. Uses the current allocation_mode to determine how much more to allocate. */
38 void reserve_more_memory();
39 public:
40 ActiveSessionMemoryStorage(allocation_mode_e allocation_mode = ALLOC_MODE_1M);
41 virtual ~ActiveSessionMemoryStorage();
43 StorageOffset get_data_size() const { return data_size; }
45 data_type_e get_offset_data_type(StorageOffset offset) const { return data_types[offset]; }
47 ActiveSessionMemoryBlock *alloc_new_block(quint64 address, quint64 size);
48 ActiveSessionMemorySnapshot *alloc_new_snapshot();
50 ActiveSessionMemorySnapshot *copy_snapshot(StorageOffset offset);
52 /** Returns the block at @a offset data offset.
53 @param offset The offset to look for a block at.
54 @return The block at @a offset, or NULL otherwise.
56 ActiveSessionMemoryBlock *get_block_at(StorageOffset offset);
57 /** Returns the snapshot at @a offset data offset.
58 @param offset The offset to look for a snapshot at.
59 @return The snapshot at @a offset, or NULL otherwise.
61 ActiveSessionMemorySnapshot *get_snapshot_at(StorageOffset offset);
64 #endif