Remove memory tracking code

This commit is contained in:
asarium committed 2016-09-08 12:22:35 +02:00
1 parent 932c05c64b
commit e0395ab51a
16 files changed
+41 -1007

No files matched your search

-5
View File
@@ -470,7 +470,6 @@ cmdline_parm dis_weapons("-dis_weapons", NULL, AT_NONE); // Cmdline_dis_weapons
cmdline_parm noparseerrors_arg("-noparseerrors", NULL, AT_NONE); // Cmdline_noparseerrors -- turns off parsing errors -C
cmdline_parm extra_warn_arg("-extra_warn", "Enable 'extra' warnings", AT_NONE); // Cmdline_extra_warn
cmdline_parm fps_arg("-fps", NULL, AT_NONE); // Cmdline_show_fps
cmdline_parm show_mem_usage_arg("-show_mem_usage", NULL, AT_NONE); // Cmdline_show_mem_usage
cmdline_parm pos_arg("-pos", NULL, AT_NONE); // Cmdline_show_pos
cmdline_parm stats_arg("-stats", NULL, AT_NONE); // Cmdline_show_stats
cmdline_parm save_render_targets_arg("-save_render_target", NULL, AT_NONE); // Cmdline_save_render_targets
@@ -499,7 +498,6 @@ int Cmdline_noparseerrors = 0;
int Cmdline_nowarn = 0; // turn warnings off in FRED
#endif
int Cmdline_extra_warn = 0;
int Cmdline_show_mem_usage = 0;
int Cmdline_show_pos = 0;
int Cmdline_show_stats = 0;
int Cmdline_save_render_targets = 0;
@@ -1658,9 +1656,6 @@ bool SetCmdlineParams()
if ( weapon_choice_3d_arg.found() )
Cmdline_weapon_choice_3d = 1;
if ( show_mem_usage_arg.found() )
Cmdline_show_mem_usage = 1;
if (ingamejoin_arg.found() )
Cmdline_ingamejoin = 1;
-1
View File
@@ -148,7 +148,6 @@ extern int Cmdline_dis_collisions;
extern int Cmdline_dis_weapons;
extern int Cmdline_noparseerrors;
extern int Cmdline_extra_warn;
extern int Cmdline_show_mem_usage;
extern int Cmdline_show_pos;
extern int Cmdline_show_stats;
extern int Cmdline_save_render_targets;
-6
View File
@@ -2,12 +2,6 @@
#ifndef _FSMEMORY_H
#define _FSMEMORY_H
#ifndef NDEBUG
#include "globalincs/memory/debug.h"
#else
#include "globalincs/memory/release.h"
#endif
#include "globalincs/memory/memory.h"
#include "globalincs/memory/utils.h"
-43
View File
@@ -1,43 +0,0 @@
#ifndef NDEBUG
#include "debug.h"
#include "globalincs/pstypes.h"
// Generic non-quiet version that just call the specialized versions
void *_vm_malloc(size_t size, const char *filename, int line)
{
auto ptr = _vm_malloc(size, memory::quiet_alloc, filename, line);
if (ptr == nullptr)
{
memory::out_of_memory(filename, line);
}
return ptr;
}
void *_vm_realloc(void *ptr, size_t size, const char *filename, int line)
{
auto ret_ptr = _vm_realloc(ptr, size, memory::quiet_alloc, filename, line);
if (ret_ptr == nullptr)
{
memory::out_of_memory(filename, line);
}
return ret_ptr;
}
void* malloc_location(size_t size, const char* location, int line)
{
return _vm_malloc(size, location, line);
}
void free_location(void* ptr, const char* location, int line)
{
_vm_free(ptr, location, line);
}
#endif
-43
View File
@@ -1,43 +0,0 @@
#pragma once
#ifdef NDEBUG
#error Debug memory management header included in release build!
#endif
#include <stdexcept>
#include "globalincs/memory/memory.h"
#include "globalincs/scp_defines.h"
namespace memory
{
// Called to initialize memory tracking in debug builds
void debug_init();
void debug_exit();
}
// Allocates some RAM.
void *_vm_malloc(size_t size, const char *filename, int line);
void *_vm_malloc(size_t size, const memory::quiet_alloc_t&, const char *filename, int line);
// Frees some RAM.
void _vm_free(void *ptr, const char *filename, int line);
// reallocates some RAM
void *_vm_realloc(void *ptr, size_t size, const char *filename, int line);
void *_vm_realloc(void *ptr, size_t size, const memory::quiet_alloc_t&, const char *filename, int line);
// Easy to use macros
#define vm_malloc(...) _vm_malloc(__VA_ARGS__,__FILE__,__LINE__)
#define vm_free(...) _vm_free(__VA_ARGS__,__FILE__,__LINE__)
#define vm_realloc(...) _vm_realloc(__VA_ARGS__,__FILE__,__LINE__)
// Version with explicit location information
void* malloc_location(size_t size, const char* location, int line);
void free_location(void* ptr, const char* location, int line);
// untracked versions DON'T USE IN NORMAL CODE!!
void* malloc_untracked(size_t size);
void free_untracked(void* ptr);
-139
View File
@@ -1,139 +0,0 @@
#ifndef NDEBUG
// Include this first!
#include "globalincs/memory/debug.h"
#include "globalincs/pstypes.h"
#include <cstdlib>
#include <stdlib.h>
#include <type_traits>
#ifdef HAVE_STD_MAX_ALIGN_T
#include <cstddef>
typedef std::max_align_t my_max_align_t;
#elif defined(HAVE_MAX_ALIGN_T)
#include <stddef.h>
typedef ::max_align_t my_max_align_t;
#else
#error This code requires the max_align_t type!
#endif
namespace
{
struct alignas(my_max_align_t) MemoryHeader
{
const char *filename;
size_t size;
int line;
};
void* getMemoryBegin(void* user_block)
{
auto mem = reinterpret_cast<uint8_t*>(user_block);
return reinterpret_cast<void*>(mem - sizeof(MemoryHeader));
}
void* getUserMemory(void* actual_block) {
auto mem = reinterpret_cast<uint8_t*>(actual_block);
return reinterpret_cast<void*>(mem + sizeof(MemoryHeader));
}
}
namespace memory
{
// Called to initialize memory tracking in debug builds
void debug_init()
{
// Do nothing in the generic version
}
void debug_exit()
{
// Do nothing in the generic version
}
}
void *_vm_malloc(size_t size, const memory::quiet_alloc_t &, const char *filename, int line)
{
auto ptr = std::malloc(sizeof(MemoryHeader) + size);
if (ptr != nullptr)
{
memory::register_malloc(size, filename, line);
auto header = reinterpret_cast<MemoryHeader *>(ptr);
header->size = size;
header->filename = filename;
header->line = line;
ptr = getUserMemory(ptr);
}
return ptr;
}
void _vm_free(void *ptr, const char *filename, int line)
{
if (!ptr)
{
return;
}
ptr = getMemoryBegin(ptr);
auto header = reinterpret_cast<MemoryHeader *>(ptr);
memory::unregister_malloc(header->size, header->filename, header->line);
std::free(ptr);
}
void *_vm_realloc(void *ptr, size_t size, const memory::quiet_alloc_t &, const char *filename, int line)
{
if (ptr == nullptr)
{
return _vm_malloc(size, filename, line);
}
ptr = getMemoryBegin(ptr);
auto memoryHeader = reinterpret_cast<MemoryHeader *>(ptr);
auto oldSize = memoryHeader->size;
auto oldFilename = memoryHeader->filename;
auto oldLine = memoryHeader->line;
auto ret_ptr = std::realloc(ptr, sizeof(MemoryHeader) + size);
if (ret_ptr == nullptr)
{
// realloc doesn't touch the original ptr in the case of failure so we could still use it
return nullptr;
}
memory::unregister_malloc(oldSize, oldFilename, oldLine);
auto header = reinterpret_cast<MemoryHeader *>(ret_ptr);
header->filename = filename;
header->line = line;
header->size = size;
memory::register_malloc(size, filename, line);
return getUserMemory(ret_ptr);
}
void *malloc_untracked(size_t size)
{
return std::malloc(size);
}
void free_untracked(void *ptr)
{
std::free(ptr);
}
#endif
-144
View File
@@ -1,144 +0,0 @@
// Only compile in debug builds
#ifndef NDEBUG
#include "debug.h"
#include "globalincs/pstypes.h"
#include <crtdbg.h>
namespace
{
const int UNTRACKED_SUBTYPE = 5;
const int UNTRACKED_BLOCK = _CLIENT_BLOCK | (UNTRACKED_SUBTYPE << 16);
// From https://msdn.microsoft.com/en-us/library/974tc9t1.aspx
// IMPORTANT: For some reason the MS documentation is wrong, the nBlockUse and nDataSize fields are switched
typedef struct _CrtMemBlockHeader
{
// Pointer to the block allocated just before this one:
struct _CrtMemBlockHeader *pBlockHeaderNext;
// Pointer to the block allocated just after this one:
struct _CrtMemBlockHeader *pBlockHeaderPrev;
char *szFileName; // File name
int nLine; // Line number
#if SCP_COMPILER_VERSION_MAJOR >= 19
// m!m - I am assuming here that the change of the block header got introduced in my version of VS
// If memory allocation seems off, check here
int nBlockUse; // Type of block
size_t nDataSize; // Size of user block
#else
size_t nDataSize; // Size of user block
int nBlockUse; // Type of block
#endif
long lRequest; // Allocation number
// Buffer just before (lower than) the user's memory:
unsigned char gap[4];
} _CrtMemBlockHeader;
_CrtMemBlockHeader* get_crt_header(void* ptr)
{
return reinterpret_cast<_CrtMemBlockHeader*>(ptr) - 1;
}
int allocation_hook(int allocType, void *userData, size_t size, int blockType,
long requestNumber, const unsigned char *filename, int lineNumber)
{
// Ignore CRT blocks
if (blockType == _CRT_BLOCK)
return 1;
// Don't record blocks allocated using the untracked_* versions
if (blockType == UNTRACKED_BLOCK)
return 1;
switch (allocType)
{
case _HOOK_ALLOC:
{
memory::register_malloc(size, reinterpret_cast<const char*>(filename), lineNumber);
break;
}
case _HOOK_FREE:
{
auto header = get_crt_header(userData);
memory::unregister_malloc(header->nDataSize, header->szFileName, header->nLine);
break;
}
case _HOOK_REALLOC:
{
if (userData == nullptr)
{
memory::register_malloc(size, reinterpret_cast<const char*>(filename), lineNumber);
}
else
{
auto header = get_crt_header(userData);
memory::unregister_malloc(header->nDataSize, header->szFileName, header->nLine);
memory::register_malloc(size, reinterpret_cast<const char*>(filename), lineNumber);
}
break;
}
default:
break;
}
return 1;
}
}
namespace memory
{
void debug_init()
{
_CrtSetAllocHook(allocation_hook);
}
void debug_exit()
{
_CrtDumpMemoryLeaks();
}
}
void *_vm_malloc(size_t size, const memory::quiet_alloc_t &, const char *filename, int line)
{
auto ptr = _malloc_dbg(size, _NORMAL_BLOCK, filename, line);
if (ptr == nullptr)
{
mprintf(("Malloc failed!!!!!!!!!!!!!!!!!!!\n"));
}
return ptr;
}
void _vm_free(void *ptr, const char*, int)
{
_free_dbg(ptr, _NORMAL_BLOCK);
}
void *_vm_realloc(void *ptr, size_t size, const memory::quiet_alloc_t &, const char *filename, int line)
{
auto ret_ptr = _realloc_dbg(ptr, size, _NORMAL_BLOCK, filename, line);
if (ret_ptr == nullptr)
{
mprintf(("Malloc failed!!!!!!!!!!!!!!!!!!!\n"));
}
return ret_ptr;
}
void* malloc_untracked(size_t size)
{
return _malloc_dbg(size, UNTRACKED_BLOCK, nullptr, -1);
}
void free_untracked(void* ptr)
{
_free_dbg(ptr, UNTRACKED_BLOCK);
}
#endif
+6 -284
View File
@@ -1,289 +1,11 @@
#include "globalincs/memory/memory.h"
#ifndef NDEBUG
#include "globalincs/memory/debug.h"
#endif
#include "globalincs/pstypes.h"
#include "cmdline/cmdline.h"
#include <unordered_map>
#include <mutex>
#include <algorithm>
#ifdef new
#undef new
#endif
namespace
{
// We need to use an allocator that uses std::malloc specifically so we don't cause infinite recursion
template<class T>
struct malloc_allocator
{
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T *pointer;
typedef const T *const_pointer;
typedef T &reference;
typedef const T &const_reference;
typedef T value_type;
template<class U>
struct rebind
{
typedef malloc_allocator<U> other;
};
malloc_allocator() SCP_NOEXCEPT
{ }
malloc_allocator(const malloc_allocator &) SCP_NOEXCEPT
{ }
template<class U>
malloc_allocator(const malloc_allocator<U> &) SCP_NOEXCEPT
{ }
~malloc_allocator() throw()
{ }
pointer address(reference x) const
{ return &x; }
const_pointer address(const_reference x) const
{ return &x; }
pointer allocate(size_type s, void const * = 0)
{
if (0 == s)
return NULL;
pointer temp = (pointer) malloc_untracked(s * sizeof(T));
if (temp == NULL)
throw std::bad_alloc();
return temp;
}
void deallocate(pointer p, size_type)
{
free_untracked(p);
}
size_type max_size() const throw()
{
return std::numeric_limits<size_t>::max() / sizeof(T);
}
void construct(pointer p, const T &val)
{
new((void *) p) T(val);
}
void destroy(pointer p)
{
p->~T();
}
};
struct MemoryInformation
{
const char *filename;
size_t memory;
};
struct string_hash
{
size_t operator()(const char *s) const
{
size_t hash = 0;
auto len = std::strlen(s);
for (size_t i = 0; i < len; ++i)
hash = 65599 * hash + s[i];
return hash ^ (hash >> 16);
}
};
struct string_equal
{
bool operator()(const char *s1, const char *s2) const
{
return std::strcmp(s1, s2) == 0;
}
};
bool meminfo_sort_compare(const MemoryInformation &arg1, const MemoryInformation &arg2)
{
return arg1.memory > arg2.memory;
}
typedef std::unordered_map<const char *, MemoryInformation,
string_hash, string_equal,
malloc_allocator<std::pair<const char *const, MemoryInformation>>> MemoryAllocationMap;
typedef std::vector<MemoryInformation, malloc_allocator<MemoryInformation>> MemoryAllocationVector;
MemoryAllocationMap *allocationMap = nullptr;
// Buffer for sorting
MemoryAllocationVector allocationVector;
size_t usedMemory = 0;
std::mutex reportLock;
void memory_uninit()
{
#ifndef NDEBUG
memory::debug_exit();
#endif
if (allocationMap != nullptr)
{
// Need to make sure we don't call the overridden operators
allocationMap->~MemoryAllocationMap();
free_untracked(allocationMap);
allocationMap = nullptr;
}
}
namespace memory {
const quiet_alloc_t quiet_alloc;
void out_of_memory() {
mprintf(("Memory allocation failed!!!!!!!!!!!!!!!!!!!\n"));
Error(LOCATION, "Out of memory. Try closing down other applications, increasing your\n"
"virtual memory size, or installing more physical RAM.\n");
}
namespace memory
{
const quiet_alloc_t quiet_alloc;
void init()
{
#ifndef NDEBUG
memory::debug_init();
allocationMap = new(malloc_untracked(sizeof(*allocationMap))) MemoryAllocationMap();
#endif
std::atexit(memory_uninit);
}
size_t get_used_memory()
{
return usedMemory;
}
size_t sort_memory_blocks()
{
if (allocationMap == nullptr)
{
return 0;
}
allocationVector.clear();
allocationVector.reserve(allocationMap->size());
for (auto &kv : *allocationMap)
{
allocationVector.push_back(kv.second);
}
std::sort(allocationVector.begin(), allocationVector.end(), meminfo_sort_compare);
return allocationVector.size();
}
bool get_memory_block(size_t index, const char *&fileName, size_t &memory)
{
if (index >= allocationVector.size())
{
return false;
}
auto &entry = allocationVector[index];
fileName = entry.filename;
memory = entry.memory;
return true;
}
// Memory tracking functions
void register_malloc(size_t size, const char *filename, int)
{
// MSVC <= 2013 somehow allocates memory when locking a mutex
// MSVC >= 2015 should be fine, for earlier version this probably means
// that the values will be corrupted but at least they will be able to run...
#if !SCP_COMPILER_IS_MSVC || SCP_COMPILER_VERSION_MAJOR >= 19
std::lock_guard<std::mutex> guard(reportLock);
#endif
usedMemory += size;
if (filename == nullptr)
{
// Origin not known
filename = "<Unknown>";
}
if (Cmdline_show_mem_usage && allocationMap != nullptr)
{
auto foundIter = allocationMap->find(filename);
if (foundIter == allocationMap->end())
{
MemoryInformation newVal;
newVal.filename = filename;
newVal.memory = 0;
foundIter = allocationMap->insert(std::make_pair(filename, newVal)).first;
}
foundIter->second.memory += size;
}
}
void unregister_malloc(size_t size, const char *filename, int)
{
// MSVC <= 2013 somehow allocates memory when locking a mutex
// MSVC >= 2015 should be fine, for earlier version this probably means
// that the values will be corrupted but at least they will be able to run...
#if !SCP_COMPILER_IS_MSVC || SCP_COMPILER_VERSION_MAJOR >= 19
std::lock_guard<std::mutex> guard(reportLock);
#endif
usedMemory -= size;
if (filename == nullptr)
{
// Origin not known
filename = "<Unknown>";
}
if (Cmdline_show_mem_usage && allocationMap != nullptr)
{
auto foundIter = allocationMap->find(filename);
if (foundIter == allocationMap->end())
{
MemoryInformation newVal;
newVal.filename = filename;
newVal.memory = 0;
foundIter = allocationMap->insert(std::make_pair(filename, newVal)).first;
}
if (size > foundIter->second.memory)
{
// We freed more memory than allocated for this file
// This can happen if one file allocates memory and another deallocates it
foundIter->second.memory = 0;
}
else
{
foundIter->second.memory -= size;
}
}
}
void out_of_memory(const char *filename, int line)
{
mprintf(("Memory allocation failed!!!!!!!!!!!!!!!!!!!\n"));
Error(filename, line, "Out of memory. Try closing down other applications, increasing your\n"
"virtual memory size, or installing more physical RAM.\n");
}
}
+35 -9
View File
@@ -2,21 +2,47 @@
#pragma once
#include <stddef.h>
#include <cstdlib>
#include "globalincs/pstypes.h"
namespace memory
{
void init();
size_t get_used_memory();
struct quiet_alloc_t { quiet_alloc_t(){} };
extern const quiet_alloc_t quiet_alloc;
void register_malloc(size_t size, const char *filename, int line);
void unregister_malloc(size_t size, const char *filename, int line);
void out_of_memory();
}
size_t sort_memory_blocks();
bool get_memory_block(size_t index, const char*& fileName, size_t& usedMemory);
inline void *vm_malloc(size_t size, const memory::quiet_alloc_t &)
{ return std::malloc(size); }
void out_of_memory(const char* filename, int line);
inline void *vm_malloc(size_t size)
{
auto ptr = vm_malloc(size, memory::quiet_alloc);
if (ptr == NULL)
{
memory::out_of_memory();
}
return ptr;
}
inline void vm_free(void *ptr)
{ std::free(ptr); }
inline void *vm_realloc(void *ptr, size_t size, const memory::quiet_alloc_t &)
{ return std::realloc(ptr, size); }
inline void *vm_realloc(void *ptr, size_t size)
{
auto ret_ptr = vm_realloc(ptr, size, memory::quiet_alloc);
if (ret_ptr == NULL)
{
memory::out_of_memory();
}
return ret_ptr;
}
-63
View File
@@ -1,63 +0,0 @@
#include "globalincs/pstypes.h"
// Compile new version of new and delete which replace the ones provided by the runtime
// This will make sure that everyone uses our operators
#ifdef new
#undef new
#endif
// throw
void * operator new (size_t size)
{
void *p = vm_malloc(size, memory::quiet_alloc);
if ( !p ) {
throw std::bad_alloc();
}
return p;
}
void operator delete (void *p) SCP_NOEXCEPT
{
vm_free(p);
}
void * operator new [] (size_t size)
{
void *p = vm_malloc(size, memory::quiet_alloc);
if ( !p ) {
throw std::bad_alloc();
}
return p;
}
void operator delete [] (void *p) SCP_NOEXCEPT
{
vm_free(p);
}
// no-throw
void * operator new (size_t size, const std::nothrow_t&) SCP_NOEXCEPT
{
return vm_malloc(size, memory::quiet_alloc);
}
void operator delete (void *p, const std::nothrow_t&) SCP_NOEXCEPT
{
vm_free(p);
}
void * operator new [] (size_t size, const std::nothrow_t&) SCP_NOEXCEPT
{
return vm_malloc(size, memory::quiet_alloc);
}
void operator delete [] (void *p, const std::nothrow_t&) SCP_NOEXCEPT
{
vm_free(p);
}
-65
View File
@@ -1,65 +0,0 @@
#pragma once
#ifndef NDEBUG
#error Release memory management header included in debug build!
#endif
#include <cstdlib>
#include "globalincs/pstypes.h"
#include "globalincs/memory/memory.h"
inline void *vm_malloc(size_t size, const memory::quiet_alloc_t &)
{ return std::malloc(size); }
inline void *vm_malloc(size_t size)
{
auto ptr = vm_malloc(size, memory::quiet_alloc);
if (ptr == NULL)
{
memory::out_of_memory("Unknown", -1);
}
return ptr;
}
inline void vm_free(void *ptr)
{ std::free(ptr); }
inline void *vm_realloc(void *ptr, size_t size, const memory::quiet_alloc_t &)
{ return std::realloc(ptr, size); }
inline void *vm_realloc(void *ptr, size_t size)
{
auto ret_ptr = vm_realloc(ptr, size, memory::quiet_alloc);
if (ret_ptr == NULL)
{
memory::out_of_memory("Unknown", -1);
}
return ret_ptr;
}
inline void* malloc_location(size_t size, const char*, int)
{
return vm_malloc(size);
}
inline void free_location(void* ptr, const char*, int)
{
vm_free(ptr);
}
// untracked versions DON'T USE IN NORMAL CODE!!
inline void *malloc_untracked(size_t size)
{
return std::malloc(size);
}
inline void free_untracked(void *ptr)
{
std::free(ptr);
}
-21
View File
@@ -4,17 +4,9 @@
#include "globalincs/pstypes.h"
#ifndef NDEBUG
inline char *_vm_strndup(const char *ptr, size_t size, const char *filename, int line)
#else
inline char *vm_strndup(const char *ptr, size_t size)
#endif
{
#ifndef NDEBUG
char *dst = (char *) _vm_malloc(size + 1, filename, line);
#else
char *dst = (char *) vm_malloc(size + 1);
#endif
if (!dst)
return NULL;
@@ -26,22 +18,9 @@ inline char *vm_strndup(const char *ptr, size_t size)
return dst;
}
#ifndef NDEBUG
inline char *_vm_strdup(const char *ptr, const char *filename, int line)
#else
inline char *vm_strdup(const char *ptr)
#endif
{
size_t len = std::strlen(ptr);
#ifndef NDEBUG
return _vm_strndup(ptr, len, filename, line);
#else
return vm_strndup(ptr, len);
#endif
}
#ifndef NDEBUG
#define vm_strdup(ptr) _vm_strdup((ptr),__FILE__,__LINE__)
#define vm_strndup(ptr, size) _vm_strndup((ptr),(size),__FILE__,__LINE__)
#endif
-20
View File
@@ -66,7 +66,6 @@ CFILE *ss_fp = NULL; // file pointer used to dump subsystem information
char model_filename[_MAX_PATH]; // temp used to store filename
char debug_name[_MAX_PATH];
int ss_warning_shown = 0; // have we shown the warning dialog concerning the subsystems?
int Model_ram = 0; // How much RAM the models use total
#endif
static uint Global_checksum = 0;
@@ -194,10 +193,6 @@ void model_unload(int modelnum, int force)
// to get the slots back so we set "release" to true.
model_page_out_textures(pm->id, true);
#ifndef NDEBUG
Model_ram -= pm->ram_used;
#endif
safe_kill(pm->ship_bay);
if (pm->paths) {
@@ -444,10 +439,6 @@ void model_init()
return;
}
#ifndef NDEBUG
Model_ram = 0;
#endif
for (i=0;i<MAX_POLYGON_MODELS;i++) {
Polygon_models[i] = NULL;
}
@@ -2636,10 +2627,6 @@ int model_load(char *filename, int n_subsystems, model_subsystem *subsystems, in
if ( !model_initted )
model_init();
#ifndef NDEBUG
size_t ram_before = memory::get_used_memory();
#endif
num = -1;
for (i=0; i< MAX_POLYGON_MODELS; i++) {
@@ -2896,13 +2883,6 @@ int model_load(char *filename, int n_subsystems, model_subsystem *subsystems, in
}
}
#ifndef NDEBUG
size_t ram_after = memory::get_used_memory();
pm->ram_used = static_cast<int>(ram_after - ram_before);
Model_ram += pm->ram_used;
#endif
// Goober5000 - originally done in ship_create for no apparent reason
model_set_subsys_path_nums(pm, n_subsystems, subsystems);
model_set_bay_path_nums(pm);
-18
View File
@@ -268,27 +268,9 @@ ENDIF(WIN32)
set(file_root_globalincs_memory
globalincs/memory/memory.h
globalincs/memory/memory.cpp
globalincs/memory/newdelete.cpp
globalincs/memory/debug.h
globalincs/memory/debug.cpp
globalincs/memory/release.h
globalincs/memory/utils.h
)
# Add conditions for compiler specialization
if (MSVC)
set(file_root_globalincs_memory
${file_root_globalincs_memory}
globalincs/memory/debug_msvc.cpp
)
else()
# If no compiler matches, use the default version
set(file_root_globalincs_memory
${file_root_globalincs_memory}
globalincs/memory/debug_generic.cpp
)
endif()
set(file_root_globalincs_toolchain
globalincs/toolchain/clang.h
globalincs/toolchain/doxygen.h
-1
View File
@@ -281,7 +281,6 @@ bool fred_init(os::GraphicsOperations* graphicsOps)
char palette_filename[1024];
SDL_SetMainReady();
memory::init();
srand( (unsigned) time(NULL) );
init_pending_messages();
-145
View File
@@ -260,10 +260,8 @@ fix FrametimeOverall = 0;
#ifndef NDEBUG
int Show_framerate = 1;
int Show_mem = 1;
#else
int Show_framerate = 0;
int Show_mem = 0;
#endif
int Framerate_cap = 120;
@@ -1191,42 +1189,6 @@ void game_loading_callback(int count)
}
#endif
#ifndef NDEBUG
if(Cmdline_show_mem_usage)
{
int line_height = gr_get_font_height() + 1;
size_t i;
char mem_buffer[1000];
memory::sort_memory_blocks();
for(i = 0; i < 30; i++)
{
const char* full_name;
size_t size;
if (!memory::get_memory_block(i, full_name, size))
{
break;
}
size /= 1024;
if(size == 0)
break;
const char *short_name = strrchr(full_name, DIR_SEPARATOR_CHAR);
if(short_name == NULL)
short_name = full_name;
else
short_name++;
sprintf(mem_buffer,"%s:\t" SIZE_T_ARG " K", short_name, size);
gr_string( 20, 220 + (int)(i*line_height), mem_buffer, GR_RESIZE_MENU);
}
sprintf(mem_buffer,"Total RAM:\t" SIZE_T_ARG " K", memory::get_used_memory() / 1024);
gr_string( 20, 230 + (int)(i*line_height), mem_buffer, GR_RESIZE_MENU);
}
#endif // !NDEBUG
os_ignore_events();
if (do_flip)
@@ -1547,37 +1509,6 @@ DCF(warp, "Tests warpin effect")
}
DCF(show_mem,"Toggles showing mem usage")
{
bool process = true;
if (dc_optional_string_either("help", "--help")) {
dc_printf( "Usage: (optional) bool Show_mem\n If true, Show_mem is set and Show_cpu is cleared. If false, then Show_mem is cleared. If nothing passed, then toggle.\n" );
process = false;
}
if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
dc_printf("Show_mem is %s\n", (Show_mem ? "TRUE" : "FALSE"));
dc_printf("Show_cpu is %s\n", (Show_cpu ? "TRUE" : "FALSE"));
process = false;
}
if (!process) {
// Help and/or status was given, so don't process the command
return;
} // Else, process the command
if (!dc_maybe_stuff_boolean(&Show_mem)) {
// Nothing passed, so toggle
Show_mem = !Show_mem;
} // Else, value was set/cleared by user
// Can't show mem and cpu at same time
if (Show_mem) {
Show_cpu = false;
}
}
DCF(show_cpu,"Toggles showing cpu usage")
{
bool process = true;
@@ -1589,7 +1520,6 @@ DCF(show_cpu,"Toggles showing cpu usage")
if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
dc_printf("Show_cpu is %s\n", (Show_cpu ? "TRUE" : "FALSE"));
dc_printf("Show_mem is %s\n", (Show_mem ? "TRUE" : "FALSE"));
process = false;
}
@@ -1602,11 +1532,6 @@ DCF(show_cpu,"Toggles showing cpu usage")
// Nothing passed, so toggle
Show_cpu = !Show_cpu;
} // Else, value was set/cleared by user
// Can't show mem and cpu at same time
if (Show_cpu) {
Show_mem = false;
}
}
#endif
@@ -2275,40 +2200,6 @@ void game_show_framerate()
sy += line_height;
}
}
if ( Show_mem ) {
int sx,sy;
sx = gr_screen.center_offset_x + gr_screen.center_w - 154;
sy = gr_screen.center_offset_y + 15;
gr_set_color_fast(&HUD_color_debug);
{
gr_printf_no_resize( sx, sy, NOX("DYN: " SIZE_T_ARG " KB\n"), memory::get_used_memory()/1024 );
sy += line_height;
}
{
extern int Model_ram;
gr_printf_no_resize( sx, sy, NOX("POF: %d KB\n"), Model_ram/1024 );
sy += line_height;
}
gr_printf_no_resize( sx, sy, NOX("%s: %d KB\n"), (Cmdline_cache_bitmaps) ? NOX("C-BMP") : NOX("BMP"), bm_texture_ram/1024 );
sy += line_height;
gr_printf_no_resize( sx, sy, NOX("S-SRAM: %d KB\n"), Snd_sram/1024 ); // mem used to store game sound
sy += line_height;
{
extern int GL_textures_in;
extern size_t GL_vertex_data_in;
gr_printf_no_resize( sx, sy, NOX("VRAM: " SIZE_T_ARG " KB\n"), (GL_textures_in + GL_vertex_data_in)/1024 );
sy += line_height;
}
}
if ( Show_player_pos ) {
int sx, sy;
@@ -2317,40 +2208,6 @@ void game_show_framerate()
gr_printf_no_resize(sx, sy, NOX("Player Pos: (%d,%d,%d)"), fl2i(Player_obj->pos.xyz.x), fl2i(Player_obj->pos.xyz.y), fl2i(Player_obj->pos.xyz.z));
}
if(Cmdline_show_mem_usage)
{
size_t i;
char mem_buffer[1000];
memory::sort_memory_blocks();
for(i = 0; i < 30; i++)
{
const char* full_name;
size_t size;
if (!memory::get_memory_block(i, full_name, size))
{
break;
}
size /= 1024;
if(size == 0)
break;
const char *short_name = strrchr(full_name, DIR_SEPARATOR_CHAR);
if(short_name == NULL)
short_name = full_name;
else
short_name++;
sprintf(mem_buffer,"%s:\t" SIZE_T_ARG " K", short_name, size);
gr_string( 20, 220 + (int)(i*line_height), mem_buffer, GR_RESIZE_MENU);
}
sprintf(mem_buffer,"Total RAM:\t" SIZE_T_ARG " K", memory::get_used_memory() / 1024);
gr_string( 20, 230 + (int)(i*line_height), mem_buffer, GR_RESIZE_MENU);
}
MONITOR_INC(NumPolys, modelstats_num_polys);
MONITOR_INC(NumPolysDrawn, modelstats_num_polys_drawn );
MONITOR_INC(NumVerts, modelstats_num_verts );
@@ -8584,8 +8441,6 @@ int actual_main(int argc, char *argv[])
int result = -1;
Assert(argc > 0);
memory::init();
#ifdef WIN32
// Don't let more than one instance of FreeSpace run.
HWND hwnd = FindWindow(NOX("FreeSpaceClass"), NULL);