ArrayBufferBuilder::ArrayBufferBuilder() : bytes_used_(0), variable_capacity_(true) { buffer_ = ArrayBuffer::Create(kDefaultBufferCapacity, 1); }
here buffer_ will be equal to an arraybuffer of 32768 bytes in length ? since the KdefaultBuffer... is set to that value.
is std::numeric_limits<unsigned>::max(); referring to the max unsigned int value ? cause the source code won't find it
--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Oh and one more thing, i've surfed perhaps the entire source code of v8 at least the interesting parts, but what i came across was just very short code execpt for some builtins written in javascript i believe, can't find all of the things i've found on the documentation such as the interpreter
and the JIT compilers,
one more thing i'd like to understand how the memory is handeled like how can i read about the JIT pages,
or which memory allocator does v8 use
and it's garbage collector
I don't quite see if this google group is useful or not, everybody keeps answering me with superficial things,
i don't care about the trminology like tell me which allocator it uses when and why or at least if there's something i can read to understand.....I'm surprised u don't know what a JIT page is, basically if you call a function foo() let's say 100 times then v8,had enough time to understand the parameters given to that specific function and how to optimize it efficently based on it's prediction/observation.I'm not interested in the terminology of things, (that's just a matter of reading the source code ) i'm more in reading how it works when and why..
For example when is ArrayBufferBuilder::Append called ??
namespace WTF { // A utility class to build an ArrayBuffer instance. Validity must be checked // by isValid() before using an instance. class WTF_EXPORT ArrayBufferBuilder final { // Disallow copying since it's expensive and we don't want code to do it by // accident. USING_FAST_MALLOC(ArrayBufferBuilder); public: // Creates an ArrayBufferBuilder using the default capacity. ArrayBufferBuilder(); ArrayBufferBuilder(unsigned capacity) : bytes_used_(0), variable_capacity_(true) { buffer_ = ArrayBuffer::Create(capacity, 1); } bool IsValid() const { return buffer_.get(); } // Appending empty data is not allowed. unsigned Append(const char* data, unsigned length); // Returns the accumulated data as an ArrayBuffer instance. If needed, // creates a new ArrayBuffer instance and copies contents from the internal // buffer to it. Otherwise, returns a RefPtr pointing to the internal // buffer. scoped_refptr<ArrayBuffer> ToArrayBuffer(); // Converts the accumulated data into a String using the default encoding. String ToString(); // Number of bytes currently accumulated. unsigned ByteLength() const { return bytes_used_; } // Number of bytes allocated. unsigned Capacity() const { return buffer_->ByteLength(); } void ShrinkToFit(); const void* Data() const { return buffer_->Data(); } // If set to false, the capacity won't be expanded and when appended data // overflows, the overflowed part will be dropped. void SetVariableCapacity(bool value) { variable_capacity_ = value; } private: // Expands the size of m_buffer to size + m_bytesUsed bytes. Returns true // iff successful. If reallocation is needed, copies only data in // [0, m_bytesUsed) range. bool ExpandCapacity(unsigned size); unsigned bytes_used_; bool variable_capacity_; scoped_refptr<ArrayBuffer> buffer_; DISALLOW_COPY_AND_ASSIGN(ArrayBufferBuilder); }; } // namespace WTF
How can i understand the structure in memory of an arraybuffer and how big is the data field which is pointed by this void pointerHow are they represented in memory....How big is the data field ?
> How can i understand the structure in memory of an arraybuffer and how big is the data field which is pointed by this void pointerIt has no structure. It is just a series of linear bytes, raw memory, allocated by the memory allocator. (If you implement your own memory allocator you can catch when this happens)It's just the data(buffer) for an array.
> How are they represented in memory....It IS memory. It's nothing more (it's an array of bytes)
> How big is the data field ?If by "field", you mean, the data buffer... it's Capacity (capacity is how much it can fit) in length. But not how much is being used. (bytes_used)
If you're curious about when memory grows, reallocates, is written to, accessed... it might be worth setting up your environment so you can debug it by stepping through the code as it executes. You can watch memory, (this would show what memcpy changes) see the values passed around, track when memory gets allocated etc.
Your questions are a mix of very broad, ("How does v8 work") and very specific programming questions (what is memcpy() doing)Broad questions are very hard to answer in general. ("How does a car work")
I agree, simply browsing the code doesn't give a good overview of say, how the javascript compiler works, or how memory is utilised. (How it is allocated is very simple, on the C/++ side it doesn't implement any memory management, and the array buffer/view is a view of the C-side memory)But after using it for a little while, I have found v8 in general is pretty simple. It provides an interface to C functions and memory. This is kinda what it's for.
But the point of v8 is that it does a lot of that for you. I don't REALLY need to know how the memory is tracked on the javascript side, it just works (if I'm using the API correctly)Then again, if you NEED to know how it works for a specific purpose (very restricted memory, fixing a bug), we can help you a lot more easily by answering a very specific question. ("My car's low-oil light is blinking, where do I fill it up")
If you're just curious as to how the entire v8 engine works... that's a massive ask. A lot of people work on it, and there is a lot of work and topics involved.Your best bet is reading the (limited) documentation on the wiki, and read the blog posts https://v8project.blogspot.com/ which go into quite a lot of detail on each post topic.I've not seen any real general overview (the wiki itself says it's out of date) so, stepping through all the code as it executes is probably your best bet.
class TV8Allocator : public v8::ArrayBuffer::Allocator
{
public:
virtual void* Allocate(size_t length) override;
virtual void* AllocateUninitialized(size_t length) override;
virtual void Free(void* data, size_t length) override;
};
void* TV8Allocator::Allocate(size_t length)
{
auto* Bytes = new uint8_t[length];
for ( auto i=0; i<length; i++ )
Bytes[i] = 0;
return Bytes;
}
void* TV8Allocator::AllocateUninitialized(size_t length)
{
auto* Bytes = new uint8_t[length];
return Bytes;
}
void TV8Allocator::Free(void* data, size_t length)
{
auto* data8 = reinterpret_cast<uint8_t*>(data);
delete[] data8;
}
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = &mAllocator;
> Cause i saw the code but didn't find how it handles all the possible javascript i might write into a script file....
Your computer most likely has more memory than you'll ever write in a script :)
If you're trying to work out where your script goes... arraybuffer isn't the right place.
Do you NEED to know? What exactly are you trying to achieve? (take a step back from the code and describe what you're trying to do;
are you trying to make an app? learn how memory works in c++? learn how memory is used in javascript? Why your app uses 1gb of memory?
--
First of all, i'd like to say that for me the documentation is really..... useless from a real technical point of view.So, what i'd like to understand is how v8 would compile a javascript "file" by that i mean how it would berepresented in memory which methods will be called and so on....(In the classes defined in the various v8 files, you don't get that sort of feeling about the memory allocator and such...i'd like to understand how to gather that knowledge.)Now, u said "kind of" for my question which was, when i allocate an arraybuffer in javascript will v8 call arraybufferbuilder ?But then one of my questions was how to invoke the append method?I know that if someone want's to expand an arraybuffer it will have to create another one and copy there those values...This is how i have a rough vision of the arraybuffer in memory:buffer ------------> [ DATA ]"simple pointer" "size of the bytes which i can manipulate with a typedarray"
| size_t len = sack_vfs_size( file ); uint8_t *buf = NewArray( uint8_t, len ); sack_vfs_read( file, (char*)buf, len ); Local<Object> arrayBuffer = ArrayBuffer::New( isolate, buf, len ); |
--
But can someone help me understand the arraybuffer part ? How to call arraybuffer::append and when I create an instance of a arraybuffer it will create it with maximum size so 37... bytes and will only say that the bytes used are the one which I’ve declared ?
Oh one more thing, so each tab in chrome is handeled as a single process, but Is the same process sandboxes with the Windows 10 kernel. Security or there’s another process which is sandboxes and then the main tab process the ( renderer ) is executed inside of it ?
Still no one ?
I was reading this code but i can't figure outwhat av_..._.. stands for
is it already opening the connection here?
static int tcp_open(URLContext *h, const char *uri, int flags) { struct addrinfo hints = { 0 }, *ai, *cur_ai; int port, fd = -1; TCPContext *s = h->priv_data; const char *p; char buf[256]; int ret; char hostname[1024],proto[1024],path[1024]; char portstr[10]; s->open_timeout = 5000000; av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port, path, sizeof(path), uri); if (strcmp(proto, "tcp")) return AVERROR(EINVAL); if (port <= 0 || port >= 65536) { av_log(h, AV_LOG_ERROR, "Port missing in uri\n"); return AVERROR(EINVAL); } p = strchr(uri, '?'); if (p) { if (av_find_info_tag(buf, sizeof(buf), "listen", p)) { char *endptr = NULL; s->listen = strtol(buf, &endptr, 10); /* assume if no digits were found it is a request to enable it */ if (buf == endptr) s->listen = 1; } if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) { s->rw_timeout = strtol(buf, NULL, 10); } if (av_find_info_tag(buf, sizeof(buf), "listen_timeout", p)) { s->listen_timeout = strtol(buf, NULL, 10); } } if (s->rw_timeout >= 0) { s->open_timeout = h->rw_timeout = s->rw_timeout; } hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; snprintf(portstr, sizeof(portstr), "%d", port); if (s->listen) hints.ai_flags |= AI_PASSIVE; if (!hostname[0]) ret = getaddrinfo(NULL, portstr, &hints, &ai); else ret = getaddrinfo(hostname, portstr, &hints, &ai); if (ret) { av_log(h, AV_LOG_ERROR, "Failed to resolve hostname %s: %s\n", hostname, gai_strerror(ret)); return AVERROR(EIO); } cur_ai = ai; restart: #if HAVE_STRUCT_SOCKADDR_IN6 // workaround for IOS9 getaddrinfo in IPv6 only network use hardcode IPv4 address can not resolve port number. if (cur_ai->ai_family == AF_INET6){ struct sockaddr_in6 * sockaddr_v6 = (struct sockaddr_in6 *)cur_ai->ai_addr; if (!sockaddr_v6->sin6_port){ sockaddr_v6->sin6_port = htons(port); } } #endif fd = ff_socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol); if (fd < 0) { ret = ff_neterrno(); goto fail; } /* Set the socket's send or receive buffer sizes, if specified. If unspecified or setting fails, system default is used. */ if (s->recv_buffer_size > 0) { setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &s->recv_buffer_size, sizeof (s->recv_buffer_size)); } if (s->send_buffer_size > 0) { setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &s->send_buffer_size, sizeof (s->send_buffer_size)); } if (s->tcp_nodelay > 0) { setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &s->tcp_nodelay, sizeof (s->tcp_nodelay)); } if (s->listen == 2) { // multi-client if ((ret = ff_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen)) < 0) goto fail1; } else if (s->listen == 1) { // single client if ((ret = ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen, s->listen_timeout, h)) < 0) goto fail1; // Socket descriptor already closed here. Safe to overwrite to client one. fd = ret; } else { if ((ret = ff_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen, s->open_timeout / 1000, h, !!cur_ai->ai_next)) < 0) { if (ret == AVERROR_EXIT) goto fail1; else goto fail; } } h->is_streamed = 1; s->fd = fd; freeaddrinfo(ai); return 0; fail: if (cur_ai->ai_next) { /* Retry with the next sockaddr */ cur_ai = cur_ai->ai_next; if (fd >= 0) closesocket(fd); ret = 0; goto restart; } fail1: if (fd >= 0) closesocket(fd); freeaddrinfo(ai); return ret; }

When is it called ?
That question is probably out of scope for v8-users. The good news is, cs.chromium.org is very good at finding when things are called, how they’re used, etc.