Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
guo450212436
et
提交
a2d8b564
E
et
项目概览
guo450212436
/
et
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
et
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a2d8b564
编写于
5月 25, 2018
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
使用RecyclableMemoryStream消除解析protobuf消息new MemoryStream产生的gc
上级
d6e35fa5
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
1764 addition
and
11 deletion
+1764
-11
Server/Model/Server.Model.csproj
Server/Model/Server.Model.csproj
+4
-0
Unity/Assets/Scripts/Base/Helper/ProtobufHelper.cs
Unity/Assets/Scripts/Base/Helper/ProtobufHelper.cs
+7
-4
Unity/Assets/Scripts/Base/RecyclableMemoryStream.meta
Unity/Assets/Scripts/Base/RecyclableMemoryStream.meta
+9
-0
Unity/Assets/Scripts/Base/RecyclableMemoryStream/Events.cs
Unity/Assets/Scripts/Base/RecyclableMemoryStream/Events.cs
+205
-0
Unity/Assets/Scripts/Base/RecyclableMemoryStream/Events.cs.meta
...Assets/Scripts/Base/RecyclableMemoryStream/Events.cs.meta
+12
-0
Unity/Assets/Scripts/Base/RecyclableMemoryStream/RecyclableMemoryStream.cs
...pts/Base/RecyclableMemoryStream/RecyclableMemoryStream.cs
+888
-0
Unity/Assets/Scripts/Base/RecyclableMemoryStream/RecyclableMemoryStream.cs.meta
...ase/RecyclableMemoryStream/RecyclableMemoryStream.cs.meta
+12
-0
Unity/Assets/Scripts/Base/RecyclableMemoryStream/RecyclableMemoryStreamManager.cs
...e/RecyclableMemoryStream/RecyclableMemoryStreamManager.cs
+608
-0
Unity/Assets/Scripts/Base/RecyclableMemoryStream/RecyclableMemoryStreamManager.cs.meta
...yclableMemoryStream/RecyclableMemoryStreamManager.cs.meta
+12
-0
Unity/Unity.csproj
Unity/Unity.csproj
+7
-7
未找到文件。
Server/Model/Server.Model.csproj
浏览文件 @
a2d8b564
...
...
@@ -54,6 +54,9 @@
<Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ObjectSystemAttribute.cs" Link="Base\Object\ObjectSystemAttribute.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\OneThreadSynchronizationContext.cs" Link="Base\OneThreadSynchronizationContext.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\QueueDictionary.cs" Link="Base\QueueDictionary.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\RecyclableMemoryStream\Events.cs" Link="Base\RecyclableMemoryStream\Events.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\RecyclableMemoryStream\RecyclableMemoryStream.cs" Link="Base\RecyclableMemoryStream\RecyclableMemoryStream.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\RecyclableMemoryStream\RecyclableMemoryStreamManager.cs" Link="Base\RecyclableMemoryStream\RecyclableMemoryStreamManager.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\TryLocker.cs" Link="Base\TryLocker.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\UnOrderMultiMap.cs" Link="Base\UnOrderMultiMap.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Component\Config\ClientConfig.cs" Link="Component\Config\ClientConfig.cs" />
...
...
@@ -114,6 +117,7 @@
<ProjectReference Include="..\ThirdParty\MongodbDriver\DotNetCoreDriver\MongoDB.Driver\MongoDB.Driver.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Base\RecyclableMemoryStream\" />
<Folder Include="Component\Config\" />
<Folder Include="Module\Message\Network\KCP\" />
<Folder Include="Module\Message\Network\TCP\" />
...
...
Unity/Assets/Scripts/Base/Helper/ProtobufHelper.cs
浏览文件 @
a2d8b564
using
System
;
using
System.ComponentModel
;
using
System.IO
;
using
Microsoft.IO
;
using
ProtoBuf
;
namespace
ETModel
{
public
static
class
ProtobufHelper
{
private
static
readonly
RecyclableMemoryStreamManager
recyclableMemoryStreamManager
=
new
RecyclableMemoryStreamManager
();
public
static
byte
[]
ToBytes
(
object
message
)
{
using
(
MemoryStream
ms
=
new
MemoryStream
())
...
...
@@ -19,7 +22,7 @@ namespace ETModel
public
static
T
FromBytes
<
T
>(
byte
[]
bytes
)
{
T
t
;
using
(
MemoryStream
ms
=
new
MemoryStream
(
bytes
,
0
,
bytes
.
Length
))
using
(
MemoryStream
ms
=
recyclableMemoryStreamManager
.
GetStream
(
"protobuf"
,
bytes
,
0
,
bytes
.
Length
))
{
t
=
Serializer
.
Deserialize
<
T
>(
ms
);
}
...
...
@@ -35,7 +38,7 @@ namespace ETModel
public
static
T
FromBytes
<
T
>(
byte
[]
bytes
,
int
index
,
int
length
)
{
T
t
;
using
(
MemoryStream
ms
=
new
MemoryStream
(
bytes
,
index
,
length
))
using
(
MemoryStream
ms
=
recyclableMemoryStreamManager
.
GetStream
(
"protobuf"
,
bytes
,
index
,
length
))
{
t
=
Serializer
.
Deserialize
<
T
>(
ms
);
}
...
...
@@ -51,7 +54,7 @@ namespace ETModel
public
static
object
FromBytes
(
Type
type
,
byte
[]
bytes
)
{
object
t
;
using
(
MemoryStream
ms
=
new
MemoryStream
(
bytes
,
0
,
bytes
.
Length
))
using
(
MemoryStream
ms
=
recyclableMemoryStreamManager
.
GetStream
(
"protobuf"
,
bytes
,
0
,
bytes
.
Length
))
{
t
=
Serializer
.
NonGeneric
.
Deserialize
(
type
,
ms
);
}
...
...
@@ -67,7 +70,7 @@ namespace ETModel
public
static
object
FromBytes
(
Type
type
,
byte
[]
bytes
,
int
index
,
int
length
)
{
object
t
;
using
(
MemoryStream
ms
=
new
MemoryStream
(
bytes
,
index
,
length
))
using
(
MemoryStream
ms
=
recyclableMemoryStreamManager
.
GetStream
(
"protobuf"
,
bytes
,
index
,
length
))
{
t
=
Serializer
.
NonGeneric
.
Deserialize
(
type
,
ms
);
}
...
...
Unity/Assets/Scripts/Base/RecyclableMemoryStream.meta
0 → 100644
浏览文件 @
a2d8b564
fileFormatVersion: 2
guid: 70be99fa9645c134cb2894b12b106b3f
folderAsset: yes
timeCreated: 1527234045
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Unity/Assets/Scripts/Base/RecyclableMemoryStream/Events.cs
0 → 100644
浏览文件 @
a2d8b564
// ---------------------------------------------------------------------
// Copyright (c) 2015 Microsoft
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ---------------------------------------------------------------------
namespace
Microsoft.IO
{
using
System
;
using
System.Diagnostics.Tracing
;
public
sealed
partial
class
RecyclableMemoryStreamManager
{
[
EventSource
(
Name
=
"Microsoft-IO-RecyclableMemoryStream"
,
Guid
=
"{B80CD4E4-890E-468D-9CBA-90EB7C82DFC7}"
)]
public
sealed
class
Events
:
EventSource
{
public
static
Events
Writer
=
new
Events
();
public
enum
MemoryStreamBufferType
{
Small
,
Large
}
public
enum
MemoryStreamDiscardReason
{
TooLarge
,
EnoughFree
}
[
Event
(
1
,
Level
=
EventLevel
.
Verbose
)]
public
void
MemoryStreamCreated
(
Guid
guid
,
string
tag
,
int
requestedSize
)
{
if
(
this
.
IsEnabled
(
EventLevel
.
Verbose
,
EventKeywords
.
None
))
{
WriteEvent
(
1
,
guid
,
tag
??
string
.
Empty
,
requestedSize
);
}
}
[
Event
(
2
,
Level
=
EventLevel
.
Verbose
)]
public
void
MemoryStreamDisposed
(
Guid
guid
,
string
tag
)
{
if
(
this
.
IsEnabled
(
EventLevel
.
Verbose
,
EventKeywords
.
None
))
{
WriteEvent
(
2
,
guid
,
tag
??
string
.
Empty
);
}
}
[
Event
(
3
,
Level
=
EventLevel
.
Critical
)]
public
void
MemoryStreamDoubleDispose
(
Guid
guid
,
string
tag
,
string
allocationStack
,
string
disposeStack1
,
string
disposeStack2
)
{
if
(
this
.
IsEnabled
())
{
this
.
WriteEvent
(
3
,
guid
,
tag
??
string
.
Empty
,
allocationStack
??
string
.
Empty
,
disposeStack1
??
string
.
Empty
,
disposeStack2
??
string
.
Empty
);
}
}
[
Event
(
4
,
Level
=
EventLevel
.
Error
)]
public
void
MemoryStreamFinalized
(
Guid
guid
,
string
tag
,
string
allocationStack
)
{
if
(
this
.
IsEnabled
())
{
WriteEvent
(
4
,
guid
,
tag
??
string
.
Empty
,
allocationStack
??
string
.
Empty
);
}
}
[
Event
(
5
,
Level
=
EventLevel
.
Verbose
)]
public
void
MemoryStreamToArray
(
Guid
guid
,
string
tag
,
string
stack
,
int
size
)
{
if
(
this
.
IsEnabled
(
EventLevel
.
Verbose
,
EventKeywords
.
None
))
{
WriteEvent
(
5
,
guid
,
tag
??
string
.
Empty
,
stack
??
string
.
Empty
,
size
);
}
}
[
Event
(
6
,
Level
=
EventLevel
.
Informational
)]
public
void
MemoryStreamManagerInitialized
(
int
blockSize
,
int
largeBufferMultiple
,
int
maximumBufferSize
)
{
if
(
this
.
IsEnabled
())
{
WriteEvent
(
6
,
blockSize
,
largeBufferMultiple
,
maximumBufferSize
);
}
}
[
Event
(
7
,
Level
=
EventLevel
.
Verbose
)]
public
void
MemoryStreamNewBlockCreated
(
long
smallPoolInUseBytes
)
{
if
(
this
.
IsEnabled
(
EventLevel
.
Verbose
,
EventKeywords
.
None
))
{
WriteEvent
(
7
,
smallPoolInUseBytes
);
}
}
[
Event
(
8
,
Level
=
EventLevel
.
Verbose
)]
public
void
MemoryStreamNewLargeBufferCreated
(
int
requiredSize
,
long
largePoolInUseBytes
)
{
if
(
this
.
IsEnabled
(
EventLevel
.
Verbose
,
EventKeywords
.
None
))
{
WriteEvent
(
8
,
requiredSize
,
largePoolInUseBytes
);
}
}
[
Event
(
9
,
Level
=
EventLevel
.
Verbose
)]
public
void
MemoryStreamNonPooledLargeBufferCreated
(
int
requiredSize
,
string
tag
,
string
allocationStack
)
{
if
(
this
.
IsEnabled
(
EventLevel
.
Verbose
,
EventKeywords
.
None
))
{
WriteEvent
(
9
,
requiredSize
,
tag
??
string
.
Empty
,
allocationStack
??
string
.
Empty
);
}
}
[
Event
(
10
,
Level
=
EventLevel
.
Warning
)]
public
void
MemoryStreamDiscardBuffer
(
MemoryStreamBufferType
bufferType
,
string
tag
,
MemoryStreamDiscardReason
reason
)
{
if
(
this
.
IsEnabled
())
{
WriteEvent
(
10
,
bufferType
,
tag
??
string
.
Empty
,
reason
);
}
}
[
Event
(
11
,
Level
=
EventLevel
.
Error
)]
public
void
MemoryStreamOverCapacity
(
int
requestedCapacity
,
long
maxCapacity
,
string
tag
,
string
allocationStack
)
{
if
(
this
.
IsEnabled
())
{
WriteEvent
(
11
,
requestedCapacity
,
maxCapacity
,
tag
??
string
.
Empty
,
allocationStack
??
string
.
Empty
);
}
}
}
}
}
// This is here for .NET frameworks which don't support EventSource. We basically shim bare functionality used above to
#if NET40
namespace
System.Diagnostics.Tracing
{
public
enum
EventLevel
{
LogAlways
=
0
,
Critical
,
Error
,
Warning
,
Informational
,
Verbose
,
}
public
enum
EventKeywords
:
long
{
None
=
0x0
,
}
[
AttributeUsage
(
AttributeTargets
.
Class
)]
public
sealed
class
EventSourceAttribute
:
Attribute
{
public
string
Name
{
get
;
set
;
}
public
string
Guid
{
get
;
set
;
}
}
[
AttributeUsage
(
AttributeTargets
.
Method
)]
public
sealed
class
EventAttribute
:
Attribute
{
public
EventAttribute
(
int
id
)
{
}
public
EventLevel
Level
{
get
;
set
;
}
}
public
class
EventSource
{
public
void
WriteEvent
(
params
object
[]
unused
)
{
return
;
}
public
bool
IsEnabled
()
{
return
false
;
}
public
bool
IsEnabled
(
EventLevel
level
,
EventKeywords
keywords
)
{
return
false
;
}
}
}
#endif
Unity/Assets/Scripts/Base/RecyclableMemoryStream/Events.cs.meta
0 → 100644
浏览文件 @
a2d8b564
fileFormatVersion: 2
guid: 52cd395d4cf275c48b1f8690689d3869
timeCreated: 1527234045
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Unity/Assets/Scripts/Base/RecyclableMemoryStream/RecyclableMemoryStream.cs
0 → 100644
浏览文件 @
a2d8b564
此差异已折叠。
点击以展开。
Unity/Assets/Scripts/Base/RecyclableMemoryStream/RecyclableMemoryStream.cs.meta
0 → 100644
浏览文件 @
a2d8b564
fileFormatVersion: 2
guid: 04ecc2633820de7459b8ba26a114f62f
timeCreated: 1527234045
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Unity/Assets/Scripts/Base/RecyclableMemoryStream/RecyclableMemoryStreamManager.cs
0 → 100644
浏览文件 @
a2d8b564
此差异已折叠。
点击以展开。
Unity/Assets/Scripts/Base/RecyclableMemoryStream/RecyclableMemoryStreamManager.cs.meta
0 → 100644
浏览文件 @
a2d8b564
fileFormatVersion: 2
guid: e7f5123bf8a488045a8e48c49b605cc9
timeCreated: 1527234045
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Unity/Unity.csproj
浏览文件 @
a2d8b564
...
...
@@ -12,16 +12,13 @@
<ProjectTypeGuids>
{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
</ProjectTypeGuids>
<TargetFrameworkIdentifier>
.NETFramework
</TargetFrameworkIdentifier>
<TargetFrameworkVersion>
v4.6
</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<CompilerResponseFile>
</CompilerResponseFile>
<TargetFrameworkProfile></TargetFrameworkProfile>
<CompilerResponseFile></CompilerResponseFile>
<UnityProjectGenerator>
VSTU
</UnityProjectGenerator>
<UnityProjectType>
Game:1
</UnityProjectType>
<UnityBuildTarget>
StandaloneWindows:5
</UnityBuildTarget>
<UnityVersion>
2017.1.3p2
</UnityVersion>
<RootNamespace>
</RootNamespace>
<RootNamespace></RootNamespace>
<LangVersion>
6
</LangVersion>
</PropertyGroup>
<PropertyGroup>
...
...
@@ -170,6 +167,9 @@
<Compile
Include=
"Assets\Scripts\Base\Object\ObjectSystemAttribute.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\OneThreadSynchronizationContext.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\QueueDictionary.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\RecyclableMemoryStream\Events.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\RecyclableMemoryStream\RecyclableMemoryStream.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\RecyclableMemoryStream\RecyclableMemoryStreamManager.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\TryLocker.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\UnOrderMultiMap.cs"
/>
<Compile
Include=
"Assets\Scripts\BehaviorTreeNode\CreateUIEffect.cs"
/>
...
...
@@ -779,4 +779,4 @@
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Target
Name=
"GenerateTargetFrameworkMonikerAttribute"
/>
</Project>
\ No newline at end of file
</Project>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录