27
27
#include " node_errors.h"
28
28
#include " simdutf.h"
29
29
#include " util.h"
30
+ #include " v8-external-memory-accounter.h"
30
31
31
32
#include < climits>
32
33
#include < cstring> // memcpy
40
41
41
42
namespace node {
42
43
44
+ using v8::ExternalMemoryAccounter;
43
45
using v8::HandleScope;
44
46
using v8::Isolate;
45
47
using v8::Just;
@@ -57,7 +59,8 @@ class ExternString: public ResourceType {
57
59
public:
58
60
~ExternString () override {
59
61
free (const_cast <TypeName*>(data_));
60
- isolate ()->AdjustAmountOfExternalAllocatedMemory (-byte_length ());
62
+ external_memory_accounter_->Decrease (isolate (), byte_length ());
63
+ delete external_memory_accounter_;
61
64
}
62
65
63
66
const TypeName* data () const override {
@@ -68,9 +71,7 @@ class ExternString: public ResourceType {
68
71
return length_;
69
72
}
70
73
71
- int64_t byte_length () const {
72
- return length () * sizeof (*data ());
73
- }
74
+ size_t byte_length () const { return length () * sizeof (*data ()); }
74
75
75
76
static MaybeLocal<Value> NewFromCopy (Isolate* isolate,
76
77
const TypeName* data,
@@ -120,16 +121,19 @@ class ExternString: public ResourceType {
120
121
return MaybeLocal<Value>();
121
122
}
122
123
123
- isolate->AdjustAmountOfExternalAllocatedMemory (h_str->byte_length ());
124
-
125
124
return str;
126
125
}
127
126
128
127
inline Isolate* isolate () const { return isolate_; }
129
128
130
129
private:
131
130
ExternString (Isolate* isolate, const TypeName* data, size_t length)
132
- : isolate_(isolate), data_(data), length_(length) { }
131
+ : isolate_(isolate),
132
+ external_memory_accounter_ (new ExternalMemoryAccounter()),
133
+ data_(data),
134
+ length_(length) {
135
+ external_memory_accounter_->Increase (isolate, byte_length ());
136
+ }
133
137
static MaybeLocal<Value> NewExternal (Isolate* isolate,
134
138
ExternString* h_str);
135
139
@@ -140,6 +144,7 @@ class ExternString: public ResourceType {
140
144
Local<Value>* error);
141
145
142
146
Isolate* isolate_;
147
+ ExternalMemoryAccounter* external_memory_accounter_;
143
148
const TypeName* data_;
144
149
size_t length_;
145
150
};
0 commit comments