-
Notifications
You must be signed in to change notification settings - Fork 0
/
datacopier.go
45 lines (42 loc) · 1.35 KB
/
datacopier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
// Thread safe data copy from one slice to another
func tsdatacopy(copyfrom *int, copyto *int, list []string) []string {
//protect memory by copying only what we know we've got
*copyto = len(list)
if *copyto > 0 && *copyto > *copyfrom {
var res []string
res = make([]string, *copyto-*copyfrom)
copy(res, list[*copyfrom:*copyto])
*copyfrom = *copyto
return res
}
return []string{}
}
// Thread safe data copy from one slice to another
func pldatacopy(copyfrom *int, copyto *int, list []processLog) []processLog {
//protect memory by copying only what we know we've got
*copyto = len(list)
if *copyto > 0 && *copyto > *copyfrom {
var res []processLog
res = make([]processLog, *copyto-*copyfrom)
copy(res, list[*copyfrom:*copyto])
*copyfrom = *copyto
return res
}
return []processLog{}
}
// Thread safe data copy from one slice to another
// This method allows us to specify a length which may be safer for
// us in the long run...
func pldatacopylen(copyfrom *int, copyto *int, list []processLog, copylen int) []processLog {
//protect memory by copying only what we know we've got
*copyto = *copyto + 1
if *copyto > 0 && *copyto > *copyfrom && *copyto <= len(list) {
var res []processLog
res = make([]processLog, *copyto-*copyfrom)
copy(res, list[*copyfrom:*copyto])
*copyfrom = *copyto
return res
}
return []processLog{}
}