capacity

What is the max capacity of an ArrayList?

我的未来我决定 提交于 2019-12-12 15:25:51
问题 I know that the initial capacity of an ArrayList is 10. When this limit is exceeded, a new ArrayList is created with the capacity of (oldcapacity * 3 / 2) + 1 , and the elements are copied over. But what is the maximum capacity of an ArrayList? I was asked this question in an interview. The interviewer was not interested in the default initial capacity, but wanted to know the maximum capacity of an ArrayList. 回答1: Look in the source code: public ArrayList(int initialCapacity) { if

How to use jquery to create progress bar for loading an image?

别等时光非礼了梦想. 提交于 2019-12-12 01:18:52
问题 I want to take size in bytes of image in page at the first load page, and then create a loading bar and show it loading similar preloader of flash. But I don't know if jQuery can take size in bytes of image or not. 回答1: I think all of these answers require something server-side to determine the file-size (please correct me if I'm wrong), but it would probably be best to preload the size from server-size or do an AJAX request to determine the file-size, but the latter seems counter productive.

How to define the concept of capacity in ArrayLists?

谁说我不能喝 提交于 2019-12-11 16:14:51
问题 I understand that capacity is the number of elements or available spaces in an ArrayList that may or may not hold a value referencing an object. I am trying to understand more about the concept of capacity. So I have three questions: 1) What are some good ways to define what capacity represents from a memory standpoint? ...the (contiguous?) memory allocated to the ArrayList? ...the ArrayLists’s memory footprint on the (heap?)? 2) Then if the above is true, changing capacity requires some

Choose primary index for Global secondary index

浪子不回头ぞ 提交于 2019-12-11 14:55:42
问题 I'm reading the AWS docs about secondary indices and I don't understand the following statement: The index key does not need to have any of the key attributes from the table From what I understand GSI allows me to create a primary or sort key on an attirubte in my table after its creation. I would like to make sure I understand the statement above, does it mean exactly that I can create a primary or sort key on an attribute that is different from the current table's primary/hash key? 回答1: Yes

ByteArrayOutputStream capacity restriction

邮差的信 提交于 2019-12-11 12:33:02
问题 I create ByteArrayOutputStream barr = new ByteArrayOutputStream(1); , i.e. with capacity 1 bytes and write to it more than 1 byte barr.write("123456789000000".getBytes()); . No error occurs, I check the length of barr it is 15. Why my writing was not blocked or wrapped? Is there a way to prevent of writing more than capacity and which outputstream could be used for that? I am very limited in available memory and don`t want to write there more than my limitations define P.S. Thanks a lot for

C++ dynamic array, increasing capacity

三世轮回 提交于 2019-12-11 09:00:26
问题 I'm trying to implement a dynamic array and here is my function for increasing the capacity int* changeCapacity(int *arr, int length, int newCapacity) { int *newArr = new int[newCapacity]; if(length > newCapacity){ return 0; } else { for(int i = 0; i < length; i++){ newArr[i] = arr[i]; } delete[] arr; arr = newArr; return arr; } } This is the error i get: speicher(2465,0x7fff7cfc2310) malloc: * error for object 0x7f9742403910: pointer being freed was not allocated * set a breakpoint in malloc

Why HashMap initial capacity is not properly handled by the library?

梦想的初衷 提交于 2019-12-10 23:57:14
问题 To create HashMap/HashSet for N elements, we generally do new HashMap((int)(N/0.75F)+1) which is annoying. Why the library has not taken care of this in the first place and allows initialization like new HashMap(N) (should not rehash till N elements) taking care of this calculation (int)(N/0.75F)+1 ? 回答1: Update Updating to reflect changed question. No, there is no such standard API but it seems there is a method Maps.newHashMapWithExpectedSize(int) in guava: Creates a HashMap instance, with

writing to OutputStream having capacity restriction

二次信任 提交于 2019-12-10 22:45:48
问题 Following the question I asked before: I am implementing an ByteArrayOutputStream having capacity restriction. My main limitation is an amount of available memory. So having such stream os : When I write more than say 1MB to the output stream I need to "stop". I prefer not throw exception but write the complete contents of os output stream to the specified other output stream argument. OutputStream out; os.writeTo(out); And after that continue the writings to os from its beginning In order to

How can we limit the capacity of an NSMutableDictionary?

拥有回忆 提交于 2019-12-08 10:28:52
问题 Is there any way to create a mutable dictionary with a capacity limit rather than an initial capacity? Say you want to create a dictionary that will only ever have, at most, 100 entries. The capacity argument for the dictionary is an initial capacity that will be simply increased if you add more elements than you want so it's not suitable. 回答1: Subclass it and override addObject to check count before adding? No built-in way. Here is a basic example... not tested, missing init etc, but this is

How to get exact capacity from storage

醉酒当歌 提交于 2019-12-08 06:19:36
问题 I want to read the exact capacity from the intern storage programmatically. I's a Samsung Galaxy S7 Edge 32GB device what I am using. In the preinstalled Samsung FileManager (In German: Eigene Dateien) it shows me the total capacity of 32GB. Even in the menu => settings => Storage it shows me 32GB. (Showed in screenshots) When I use my code below it shows me a total capacity of 24,4GB. (Showed in Log at the end of the post) Question: How to get the exact 32GB total capacity of my device?