What is the maximum number of characters can dart String class can hold? I searched about this question in Google Search and I can't found the answer.
It depends.
When compiled for the web, the limit is the allowed JS String length.
Checking, it seems Chrome has a 0x1FFF_FFE8 limit on string length, Firefox uses 0x3FFF_FFFE.
On the Dart native VM, the limit is memory (and the size of integers, but so far the 64-bit integers cannot be a limiting factor on contemporary hardware. You can't actually have 2^64 bytes of memory on any current 64-bit architecture.)
I ran into "Exhausted heap space" errors after trying to double a string of length 0x4_0000_0000 (16 Gb). At that point the code was already fairly slow, which is not surprising since the computer "only" has 32 Gb of physical memory.
If using a 32-bit VM, the memory limit will definitely be lower.
Related
I was reading about some VBA performance optimisations and learned that there's a difference between optimising for memory usage versus performance in 32bit VBA applications.
An example of memory optimisation would be using the smallest variable appropriate for your application, eg using an Int instead of a Long of a Float.
For performance it appears to be about matching the variable size in bits to the OS so that it doesn't have to do any type conversions from 8bit to 32bit 'under the hood'.
Can I assume this logic extends into the 64bit version of Excel 365 running VBA7?
Ie, is a LongLong (64bit) the most performance optimised approach to working with integers at the cost of memory use versus alternatives such as the Long or Int?
EDIT: There's an answer here that shows the results of testing on 64 bit operating systems and the answer was to use Longs but the optimisation doesn't account for much in terms of time saved (13s over 1 billion operations).
In 64 bit standard integer size is 32 bits (and signed). Memory addressing is 64 bit (and unsigned). CPU is optimised for both.
The major way programs are optimised for speed versus memory is to unwind functions to inline code for speed if it can. Function calls are slow.
x64 has a faster calling convention than x32 on Windows. In x32 all parameters are passed on the stack, an area of memory so slower than a register. In x64 they are passed in registers where ever possible, ie if it runs out of registers it will pass the rest on the stack..
I've been flying around the internet today trying to wrap my head around this topic. So here's what I understood so far. So the bigger the register size the bigger the instructions a processor can handle?
Quote:
The size of the registers, which is sometimes called the word size, indicates the amount of data with which the computer can work at any given time.
Question 1:
How would this be explained in terms of dealing with RAM? Why would a 32-bit processor be less adept or slower at processing information in this case?
Also, the term addressing. So while a 64-bit processor can "address" 2^64 different locations in RAM, a 32-bit processor can only deal with 2^32.
Question 2:
What does addressing mean? And why would the ability to address more locations be more helpful?
Question 3:
How are these 2 points, 1)Number of addressable locations and 2)Instruction size, related?
I hope my questions aren't confusing. It would be nice if references and examples to RAM as well as comparisons between 32 and 64-bits would be given in the explanations.
As chux already stated, there can be a lot of different bus width's in a computer system. That said, I assume you're talking about usual PC architectures here. Now, to your questions:
Performance difference between 32 and 64 bit systems
The hardware usually is able to operate on bigger numbers than a 32 bit system, so it can e.g. sum two 64 bits numbers in one operation, while a 32 bit system would need at least two (plus some operations to combine the results). This means a software that does lots of operations in big numbers will probably be faster on a 64 bit system, but a software that don't need big numbers will not be faster
A 64 bit processor usually fetch bigger blocks of data from memory than a 32 bit one. If the data bus is 64 bits instead of 32, it'll fetch double the bytes than the 32 bit system
This is actually a negative point in 64 bit system: since you have more addressable memory, you also need more memory for pointers, so 64 bit applications will also use a little more memory than the same aplication compiled for a 32 bit system.
Memory addressing
The memory address is a number that uniquely identifies a position in memory, where data is stored. With a 32 bit number, you can adress 2^32 positions, which is roughly 4 GB. This is why 32 bit PC's cannot use more than 4 GB of memory (they actually can, with some restrictions. See PAE). Using 64 bit numbers means the computer can now address 2^64 positions, which means it could, in principle, use up to 16 exbibytes of memory. In practice, other limits prevent a PC from having all that memory.
Addressable locations vs Memory Size
Since lots of instructions should reference a memory position, this means that some of them will have to be bigger, so they have room for memory adresses.
Bigger instructions usually means bigger software code, but this is not a problem in most cases, because the difference isn't that big, and because most of software size usually is composed of data, rather than code.
Disclaimer: Not all I said is valid for every software/architecture. There are a lot of detais that may have more impact in performace and memory usage than the points I wrote here.
The bit width of a processor's registers, it addressing range and the processor internal/external bus width between the processor and RAM are independent.
A 32-bit processor commonly can handle 32-bit addresses, but it may only handle 24 or maybe 64. Many possibilities have occurred.
Addressing would the the maximum range from 0 to N-1 of unique addresses that could be generated. If there is truly N locations of memory is another matter.
The width of the bus between CPU and RAM dramatically affects performance. This width, independent of CPU reg size and RAM size, throttle throughput.
Addressing range and resister size tend to correlate. Units with wider registers usually have wider address range. There is no rule that forces these 2 to be the same.
Suggest reviewing CPU architectures and micro controller and the theoretical Turing Machine
In windows, I can check the largest contiguous free blocks via 'feature memstats'. But this does not work on linux. I am currently working on a project which needs to load a very large matrix(59107200*17). And I ran into 'out of memory' error. Is there any way to check this and other memory infomation in matlab on linux?
Have you tried memory function? I think it should be available on Linux as well.
Added
By the way, 59107200*17 array of doubles require about 8 Gb of memory (each double number occupies 8 bytes). Do you have it?
I am a newbie at matlab and I am trying to solve the following scenario.
I have large strings which need to be xor'ed essentially encoded in order to get a value.
I am using the following code snippet to perform the operation :
clear;clc;
first ='abceeeeeeeeeeeeeeeddddddddddddd';
second='defrrrrrrrrrrrrttttttttttttuuuu';
result=bitxor(uint8(double(first)) , uint8(double(second)));
In the code above I am hard coding the value of the strings. I was wondering if matlab defines a size limit on the strings? If someone could help me to understand this value more in terms of bytes it will be very helpful.
Thanks and Regards,
Bhavya
I don't think tere is a size limit attached to the variable, but there is certainly a limit in term of available memory which depends on your operating system and computer architecture.
For example, I run Matlab R2008b on a 32 bits Windows 7. The output of the command memory gives me:
Maximum possible array: 1128 MB (1.183e+009 bytes) *
Memory available for all arrays: 1470 MB (1.542e+009 bytes) **
Memory used by MATLAB: 294 MB (3.085e+008 bytes)
Physical Memory (RAM): 3519 MB (3.690e+009 bytes)
* Limited by contiguous virtual address space available.
** Limited by virtual address space available.
I can create a character array of 5e8 elements before I raise an "out of memory" error, so that is 1e9 bytes, which is in agreement with the memory output.
You can check out the technical notes related to memory management on the MathWorks website:
Maximum Matrix Size by Platform
Memory Management Guide
Avoiding 'Out of Memory' Errors
How to increase the size of the CString, if CString Object get maximum size. or tell me the function which can hold maximum data more than the CString
CString uses heap allocation for the string buffer so actual limit for the string length depends on a number of conditions and is some hundreds megabytes.
In general, each time the string needs to grow its buffer it allocates a new buffer greater then the previous one - there's a strategy for how to determine the new size of the buffer. Depending on actual amount of available memory in the system this reallocation may either fail or succeed. If it fails you have very little options of what you can do - the best choice is usually to restart the program.
For the task you solve - working with a COM port - you can use an MFC::CArray which is very convenient to use as a variable size array. You could also use std::vector for the same.
In CString, the string actual size and allocated buffer are held by signed ints (check out CStringData). The string buffer itself is dynamically allocated. This means the theoretical limit is 2^31 characters. Practically, on a 32 bit environment you'll be able to get much less due to memory fragmantation. Also, if you're using Unicode CString, each character is two bytes, which means the CString buffer will hold less text. On a 64 bit environment you might be able to get as much as 2^31 characters.
Having that said, are you really trying to work with strings that long? There's probably a lot to do before you hit the CString length limit.