Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
cdy816
Mars
提交
3ccd449a
Mars
项目概览
cdy816
/
Mars
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3ccd449a
编写于
7月 21, 2020
作者:
cdy816
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
byte数组采用池化技术实现
上级
13134655
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
13 deletion
+28
-13
Common/Cdy.Tag.Common/Common/MarshalFixedMemoryBlock.cs
Common/Cdy.Tag.Common/Common/MarshalFixedMemoryBlock.cs
+7
-3
RunTime/DBRuntime/His/Compress/CompressMemory.cs
RunTime/DBRuntime/His/Compress/CompressMemory.cs
+2
-1
RunTime/DBRuntime/His/Serise/SeriseEnginer.cs
RunTime/DBRuntime/His/Serise/SeriseEnginer.cs
+19
-9
未找到文件。
Common/Cdy.Tag.Common/Common/MarshalFixedMemoryBlock.cs
浏览文件 @
3ccd449a
...
...
@@ -7,6 +7,7 @@
// 种道洋
//==============================================================
using
System
;
using
System.Buffers
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO.MemoryMappedFiles
;
...
...
@@ -1505,12 +1506,13 @@ namespace Cdy.Tag
{
using
(
var
stream
=
System
.
IO
.
File
.
Open
(
fileName
,
FileMode
.
OpenOrCreate
,
FileAccess
.
ReadWrite
,
FileShare
.
ReadWrite
))
{
byte
[]
bvals
=
new
byte
[
1024
]
;
byte
[]
bvals
=
ArrayPool
<
byte
>.
Shared
.
Rent
(
1024
)
;
for
(
long
i
=
0
;
i
<
memory
.
Length
/
1024
;
i
++)
{
Marshal
.
Copy
(
new
IntPtr
(
memory
.
Handles
.
ToInt64
()
+
i
*
1024
),
bvals
,
0
,
1024
);
stream
.
Write
(
bvals
,
0
,
1024
);
}
ArrayPool
<
byte
>.
Shared
.
Return
(
bvals
);
stream
.
Flush
();
}
}
...
...
@@ -1523,7 +1525,7 @@ namespace Cdy.Tag
public
static
void
RecordToLog
(
this
MarshalFixedMemoryBlock
memory
,
Stream
stream
)
{
int
ls
=
1024
*
1024
*
128
;
byte
[]
bvals
=
new
byte
[
ls
];
//
byte[] bvals = new byte[ls];
//long totalsize = memory.AllocSize;
//long csize = 0;
...
...
@@ -1531,6 +1533,8 @@ namespace Cdy.Tag
int
ltmp
=
(
int
)
memory
.
AllocSize
;
var
source
=
memory
.
Handles
;
var
bvals
=
ArrayPool
<
byte
>.
Shared
.
Rent
(
ls
);
while
(
ltmp
>
0
)
{
int
ctmp
=
Math
.
Min
(
bvals
.
Length
,
ltmp
);
...
...
@@ -1539,7 +1543,7 @@ namespace Cdy.Tag
stmp
+=
ctmp
;
ltmp
-=
ctmp
;
}
ArrayPool
<
byte
>.
Shared
.
Return
(
bvals
);
//for (long i = 0; i < memory.Length / ls; i++)
//{
// Marshal.Copy(new IntPtr(memory.Handles.ToInt64() + i * ls), bvals, 0, ls);
...
...
RunTime/DBRuntime/His/Compress/CompressMemory.cs
浏览文件 @
3ccd449a
...
...
@@ -201,6 +201,7 @@ namespace Cdy.Tag
foreach
(
var
vv
in
mTagAddress
)
{
var
size
=
CompressBlockMemory
(
source
,
vv
.
Value
.
Item1
,
Offset
,
vv
.
Value
.
Item3
,
vv
.
Value
.
Item4
,
vv
.
Key
);
if
(
dtmp
.
ContainsKey
(
vv
.
Key
))
dtmp
[
vv
.
Key
]
=
Offset
;
Offset
+=
size
;
datasize
+=
size
;
...
...
@@ -224,7 +225,7 @@ namespace Cdy.Tag
ServiceLocator
.
Locator
.
Resolve
<
IDataSerialize
>().
RequestToSeriseFile
(
this
,
mCurrentTime
);
sw
.
Stop
();
LoggerService
.
Service
.
Info
(
"CompressEnginer"
,
Id
+
"压缩完成 耗时:"
+
sw
.
ElapsedMilliseconds
+
" ltmp1:"
+
ltmp1
+
" ltmp2:"
+
(
ltmp2
-
ltmp1
)
+
" ltmp3:"
+
(
ltmp3
-
ltmp2
),
ConsoleColor
.
Blue
);
LoggerService
.
Service
.
Info
(
"CompressEnginer"
,
Id
+
"压缩完成 耗时:"
+
sw
.
ElapsedMilliseconds
+
" ltmp1:"
+
ltmp1
+
" ltmp2:"
+
(
ltmp2
-
ltmp1
)
+
" ltmp3:"
+
(
ltmp3
-
ltmp2
)
+
" CPU Id:"
+
ThreadHelper
.
GetCurrentProcessorNumber
()
,
ConsoleColor
.
Blue
);
}
catch
(
Exception
ex
)
...
...
RunTime/DBRuntime/His/Serise/SeriseEnginer.cs
浏览文件 @
3ccd449a
...
...
@@ -13,6 +13,7 @@ using System.Threading;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Diagnostics
;
using
System.Buffers
;
/*
* ****文件结构****
...
...
@@ -460,10 +461,12 @@ namespace Cdy.Tag
{
DateTime
date
=
new
DateTime
(
time
.
Year
,
time
.
Month
,
time
.
Day
,
((
time
.
Hour
/
FileDuration
)
*
FileDuration
),
0
,
0
);
mFileWriter
.
Write
(
date
,
0
);
byte
[]
nameBytes
=
new
byte
[
64
];
//byte[] nameBytes = new byte[64];
byte
[]
nameBytes
=
ArrayPool
<
byte
>.
Shared
.
Rent
(
64
);
var
ntmp
=
Encoding
.
UTF8
.
GetBytes
(
databaseName
);
Buffer
.
BlockCopy
(
ntmp
,
0
,
nameBytes
,
0
,
Math
.
Min
(
64
,
ntmp
.
Length
));
mFileWriter
.
Write
(
nameBytes
,
8
);
ArrayPool
<
byte
>.
Shared
.
Return
(
nameBytes
);
}
/// <summary>
...
...
@@ -473,28 +476,29 @@ namespace Cdy.Tag
{
byte
[]
bval
;
int
totalLen
;
int
datalen
;
//更新上个DataRegion 的Next DataRegion Pointer 指针
if
(
mPreDataRegion
>=
0
)
{
mFileWriter
.
Write
(
mCurrentDataRegion
,
mPreDataRegion
+
8
);
}
bval
=
GeneratorDataRegionHeader
(
out
totalLen
);
mFileWriter
.
Append
(
bval
,
0
,
bval
.
Length
);
mFileWriter
.
AppendZore
(
totalLen
-
bval
.
Length
);
bval
=
GeneratorDataRegionHeader
(
out
totalLen
,
out
datalen
);
mFileWriter
.
Append
(
bval
,
0
,
datalen
);
mFileWriter
.
AppendZore
(
totalLen
-
datalen
);
mPreDataRegion
=
mCurrentDataRegion
;
mBlockPointOffset
=
mCurrentDataRegion
+
mBlockPointOffset
;
ArrayPool
<
byte
>.
Shared
.
Return
(
bval
);
}
/// <summary>
/// 生成区域头部
/// <paramref name="offset">偏移位置</paramref>
/// </summary>
private
byte
[]
GeneratorDataRegionHeader
(
out
int
totallenght
)
private
byte
[]
GeneratorDataRegionHeader
(
out
int
totallenght
,
out
int
datalen
)
{
Stopwatch
sw
=
new
Stopwatch
();
sw
.
Start
();
...
...
@@ -504,7 +508,9 @@ namespace Cdy.Tag
totallenght
=
len
;
using
(
System
.
IO
.
MemoryStream
mHeadMemory
=
new
System
.
IO
.
MemoryStream
())
byte
[]
bvals
=
ArrayPool
<
byte
>.
Shared
.
Rent
(
52
+
mTagIdMemoryCach
.
Position
);
using
(
System
.
IO
.
MemoryStream
mHeadMemory
=
new
System
.
IO
.
MemoryStream
(
bvals
))
{
mHeadMemory
.
Position
=
0
;
...
...
@@ -524,12 +530,13 @@ namespace Cdy.Tag
mHeadMemory
.
Write
(
mTagIdMemoryCach
.
Buffer
,
0
,
mTagIdMemoryCach
.
Position
);
//写入压缩数据
mBlockPointOffset
=
mHeadMemory
.
Position
;
datalen
=
(
int
)
mHeadMemory
.
Position
;
sw
.
Stop
();
LoggerService
.
Service
.
Info
(
"SeriseFileItem"
+
Id
,
"GeneratorDataRegionHeader "
+
sw
.
ElapsedMilliseconds
);
return
mHeadMemory
.
ToArray
();
return
bvals
;
//return mHeadMemory.ToArray();
}
}
...
...
@@ -639,6 +646,9 @@ namespace Cdy.Tag
//int blockcount = FileDuration * 60 / BlockDuration;
var
vv
=
ServiceLocator
.
Locator
.
Resolve
<
IHisEngine
>();
var
tags
=
vv
.
ListAllTags
().
Where
(
e
=>
e
.
Id
>=
Id
*
TagCountOneFile
&&
e
.
Id
<
(
Id
+
1
)
*
TagCountOneFile
).
OrderBy
(
e
=>
e
.
Id
);
if
(
mBlockPointMemory
!=
null
)
mBlockPointMemory
.
Dispose
();
mBlockPointMemory
=
new
MemoryBlock
(
tags
.
Count
()
*
8
,
1024
*
1024
);
mBlockPointMemory
.
Clear
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录