summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/sdl
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2020-10-03 02:50:49 +1000
committer Vas Crabb <vas@vastheman.com>2020-10-03 03:00:24 +1000
commit4f05917494b22943ab0e7c466e4eb9f7a5896daa (patch)
treeb05a6b7820548f21ab8df21c4e4ca034eff0659f /src/osd/sdl
parent3340fc0d2171011e3f6d7f41f0414e9d3952e364 (diff)
Got rid of global_alloc/global_free.
The global_alloc/global_free functions have outlived their usefulness. They don't allow consistently overriding the default memory allocation behaviour because they aren't used consistently, and we don't have standard library allocator wrappers for them that we'd need to use them consistently with all the standard library containers we're using. If you need to change the default allocator behaviour, you can override the new/delete operators, and there are ways to get more fine-grained control that way. We're already doing that to pre-fill memory in debug builds. Code was already starting to depend on global_alloc/global_free wrapping new/delete. For example some parts of the code (including the UI and Windows debugger) was putting the result of global_alloc in a std::unique_ptr wrappers without custom deleters, and the SPU sound device was assuming it could use global_free to release memory allocated with operator new. There was also code misunderstanding the behaviour of global_alloc, for example the GROM port cartridge code was checking for nullptr when a failure will actually throw std::bad_alloc. As well as substituting new/delete, I've made several things use smart pointers to reduce the chance of leaks, and fixed a couple of leaks, too.
Diffstat (limited to 'src/osd/sdl')
-rw-r--r--src/osd/sdl/window.cpp3
-rw-r--r--src/osd/sdl/window.h8
2 files changed, 5 insertions, 6 deletions
diff --git a/src/osd/sdl/window.cpp b/src/osd/sdl/window.cpp
index 70886d76a73..9f07ce7cd49 100644
--- a/src/osd/sdl/window.cpp
+++ b/src/osd/sdl/window.cpp
@@ -1137,12 +1137,11 @@ sdl_window_info::sdl_window_info(
m_prescale = video_config.prescale;
m_windowed_dim = osd_dim(config->width, config->height);
- m_original_mode = global_alloc(SDL_DM_Wrapper);
+ m_original_mode = std::make_unique<SDL_DM_Wrapper>();
}
sdl_window_info::~sdl_window_info()
{
- global_free(m_original_mode);
}
diff --git a/src/osd/sdl/window.h b/src/osd/sdl/window.h
index d6010e91ed2..bfe32e6e8a0 100644
--- a/src/osd/sdl/window.h
+++ b/src/osd/sdl/window.h
@@ -8,8 +8,8 @@
//
//============================================================
-#ifndef __SDLWINDOW__
-#define __SDLWINDOW__
+#ifndef MAME_OSD_SDL_WINDOW_H
+#define MAME_OSD_SDL_WINDOW_H
#include "osdsdl.h"
#include "video.h"
@@ -87,7 +87,7 @@ private:
render_target * m_target;
// Original display_mode
- SDL_DM_Wrapper *m_original_mode;
+ std::unique_ptr<SDL_DM_Wrapper> m_original_mode;
int m_extra_flags;
@@ -152,4 +152,4 @@ int drawsdl2_init(running_machine &machine, osd_draw_callbacks *callbacks);
int drawbgfx_init(running_machine &machine, osd_draw_callbacks *callbacks);
-#endif /* __SDLWINDOW__ */
+#endif // MAME_OSD_SDL_WINDOW_H