forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathByteBlock.h
More file actions
52 lines (42 loc) · 2.06 KB
/
ByteBlock.h
File metadata and controls
52 lines (42 loc) · 2.06 KB
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
46
47
48
49
50
51
52
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
namespace Js
{
class ByteBlock
{
DECLARE_OBJECT(ByteBlock)
private:
uint m_contentSize; // Length of block, in bytes
__declspec(align(4)) // Align the buffer to sizeof(uint32) to improve GetHashCode() perf.
byte* m_content; // The block's content
static ByteBlock* New(Recycler* alloc, const byte * initialContent, int initialContentSize, ScriptContext * requestContext);
public:
ByteBlock(uint size, byte * content)
: m_contentSize(size), m_content(content)
{ }
ByteBlock(uint size, Recycler *alloc) : m_contentSize(size)
{
// The New function below will copy over a buffer into this so
// we don't need to zero it out
m_content = RecyclerNewArrayLeaf(alloc, byte, size);
}
ByteBlock(uint size, ArenaAllocator* alloc) : m_contentSize(size)
{
m_content = AnewArray(alloc, byte, size);
}
static DWORD GetBufferOffset() { return offsetof(ByteBlock, m_content); }
static ByteBlock* New(Recycler* alloc, const byte * initialContent, int initialContentSize);
// This is needed just for the debugger since it allocates
// the byte block on a separate thread, which the recycler doesn't like.
// To remove when the recycler supports multi-threaded allocation.
static ByteBlock* NewFromArena(ArenaAllocator* alloc, const byte * initialContent, int initialContentSize);
uint GetLength() const;
byte* GetBuffer();
const byte* GetBuffer() const;
const byte operator[](uint itemIndex) const;
byte& operator[] (uint itemIndex);
};
} // namespace Js