Skip to content

Commit e81e4bc

Browse files
committed
vector caching to improve performance
1 parent 31f0932 commit e81e4bc

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

RemoteDesktop_GatewayExample/RemoteDesktop_GatewayExample.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234
<AutoAssignPort>True</AutoAssignPort>
235235
<DevelopmentServerPort>3406</DevelopmentServerPort>
236236
<DevelopmentServerVPath>/</DevelopmentServerVPath>
237-
<IISUrl>http://localhost:3406/</IISUrl>
237+
<IISUrl>http://scott-pc:3406/</IISUrl>
238238
<NTLMAuthentication>False</NTLMAuthentication>
239239
<UseCustomServer>False</UseCustomServer>
240240
<CustomServerUrl>

RemoteDesktop_Library/Image.h

+25-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace RemoteDesktop{
1010
extern bool GrazyScale;
1111
}
1212
namespace INTERNAL{
13+
//improves speed when memory allocations are kept down because vector resize always does a memset on the unintialized elements
1314
extern std::vector<std::vector<char>> BufferCache;
1415
extern std::mutex BufferCacheLock;
1516
}
@@ -22,23 +23,41 @@ namespace RemoteDesktop{
2223
Image(const Image& other) = delete;
2324
Image() {}
2425
explicit Image(char* d, int h, int w) :Pixel_Stride(4), Height(h), Width(w) {
25-
26+
if (!INTERNAL::BufferCache.empty()){
27+
std::lock_guard<std::mutex> lock(INTERNAL::BufferCacheLock);
28+
if (!INTERNAL::BufferCache.empty()){
29+
data = std::move(INTERNAL::BufferCache.back());
30+
INTERNAL::BufferCache.pop_back();
31+
}
32+
}
2633
data.resize(Pixel_Stride*Height*Width); memcpy(data.data(), d, Pixel_Stride);
2734
}
2835
explicit Image(int h, int w) : Pixel_Stride(4), Height(h), Width(w) {
36+
if (!INTERNAL::BufferCache.empty()){
37+
std::lock_guard<std::mutex> lock(INTERNAL::BufferCacheLock);
38+
if (!INTERNAL::BufferCache.empty()){
39+
data = std::move(INTERNAL::BufferCache.back());
40+
INTERNAL::BufferCache.pop_back();
41+
}
42+
}
2943
data.resize(Pixel_Stride*Height*Width);
3044
}
3145
Image(Image&& other) :data(std::move(other.data)), Height(std::move(other.Height)), Width(std::move(other.Width)), Compressed(std::move(other.Compressed)){
32-
46+
3347
}
3448
Image& operator=(Image&& other){
35-
49+
3650
data = std::move(other.data);
37-
Height=std::move(other.Height);
38-
Width=std::move(other.Width);
51+
Height = std::move(other.Height);
52+
Width = std::move(other.Width);
3953
Compressed = std::move(other.Compressed);
4054
}
41-
55+
~Image(){
56+
if (data.size() > 100){
57+
std::lock_guard<std::mutex> lock(INTERNAL::BufferCacheLock);
58+
INTERNAL::BufferCache.emplace_back(std::move(data));
59+
}
60+
}
4261
static Image Create_from_Compressed_Data(char* d, int size_in_bytes, int h, int w);
4362
void Compress();
4463
void Decompress();

0 commit comments

Comments
 (0)