aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelupus <elupus@xbmc.org>2011-03-24 23:33:29 +0100
committerelupus <elupus@xbmc.org>2011-03-25 20:04:27 +0100
commit93e3ecf95be0d2eeea6254e0f98a7f47e4efc691 (patch)
tree126ad2f8da4b2dbb0fb01f3acb9974b6d04ae9f3
parent580387f0eb9541246e20d236adf0e0c5348f5bc1 (diff)
added: allocate the file cache buffer as a memory mapped file in system page file
This allows allocation of quite large buffers for for the CFileCache without physically using that much system memory. The cached data will be paged out on need.
-rw-r--r--xbmc/filesystem/CacheCircular.cpp18
-rw-r--r--xbmc/filesystem/CacheCircular.h3
2 files changed, 21 insertions, 0 deletions
diff --git a/xbmc/filesystem/CacheCircular.cpp b/xbmc/filesystem/CacheCircular.cpp
index 6f656e335c..3e446963c0 100644
--- a/xbmc/filesystem/CacheCircular.cpp
+++ b/xbmc/filesystem/CacheCircular.cpp
@@ -35,6 +35,9 @@ CCacheCircular::CCacheCircular(size_t front, size_t back)
, m_buf(NULL)
, m_size(front + back)
, m_size_back(back)
+#ifdef _WIN32
+ , m_handle(INVALID_HANDLE_VALUE)
+#endif
{
}
@@ -45,7 +48,16 @@ CCacheCircular::~CCacheCircular()
int CCacheCircular::Open()
{
+#ifdef _WIN32
+ m_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, m_size, NULL);
+ if(m_handle == INVALID_HANDLE_VALUE)
+ return CACHE_RC_ERROR;
+ m_buf = (uint8_t*)MapViewOfFile(m_handle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
+#else
m_buf = new uint8_t[m_size];
+#endif
+ if(m_buf == 0)
+ return CACHE_RC_ERROR;
m_beg = 0;
m_end = 0;
m_cur = 0;
@@ -54,7 +66,13 @@ int CCacheCircular::Open()
int CCacheCircular::Close()
{
+#ifdef _WIN32
+ UnmapViewOfFile(m_buf);
+ CloseHandle(m_handle);
+ m_handle = INVALID_HANDLE_VALUE;
+#else
delete[] m_buf;
+#endif
m_buf = NULL;
return CACHE_RC_OK;
}
diff --git a/xbmc/filesystem/CacheCircular.h b/xbmc/filesystem/CacheCircular.h
index c841552828..b27db704a9 100644
--- a/xbmc/filesystem/CacheCircular.h
+++ b/xbmc/filesystem/CacheCircular.h
@@ -53,6 +53,9 @@ protected:
size_t m_size_back;
CCriticalSection m_sync;
CEvent m_written;
+#ifdef _WIN32
+ HANDLE m_handle;
+#endif
};
} // namespace XFILE