Questions tagged [capacity]

Questions about resource capacity. Use in conjunction with the applicable tag such as [memory], [disk] or [database] to indicate the type of resource being referred to.

Questions about resource capacity. Use in conjunction with the applicable tag such as , or to indicate the type of resource being referred to.

230 questions
151
votes
11 answers

Why start an ArrayList with an initial capacity?

The usual constructor of ArrayList is: ArrayList list = new ArrayList<>(); But there is also an overloaded constructor with a parameter for its initial capacity: ArrayList list = new ArrayList<>(20); Why is it useful to create an ArrayList…
Rob
  • 14,827
  • 20
  • 65
  • 104
82
votes
12 answers

Calculating usage of localStorage space

I am creating an app using the Bespin editor and HTML5's localStorage. It stores all files locally and helps with grammar, uses JSLint and some other parsers for CSS and HTML to aid the user. I want to calculate how much of the localStorage limit…
JeroenEijkhof
  • 2,122
  • 2
  • 24
  • 37
55
votes
7 answers

Default Capacity of List

What is the default capacity of a List?
Jawahar BABU
  • 825
  • 2
  • 8
  • 7
35
votes
8 answers

Default capacity of StringBuilder

What is the default capacity of a StringBuilder? And when should (or shouldn't) the default be used?
Matt Lacey
  • 64,328
  • 10
  • 87
  • 143
34
votes
8 answers

Capacity of ArrayList

Possible Duplicate: How to get the capacity of the ArrayList in Java? How to find the capacity of an ArrayList?
user430532
  • 341
  • 1
  • 3
  • 3
30
votes
3 answers

Best practice for rate limiting users of a REST API?

I am putting together a REST API and as I'm unsure how it will scale or what the demand for it will be, I'd like to be able to rate limit uses of it as well as to be able to temporarily refuse requests when the box is over capacity or if there is…
frankodwyer
  • 13,712
  • 8
  • 48
  • 70
29
votes
4 answers

Does clearing a vector affect its capacity?

I instantiate an std::vector foo(1000). foo.size() is now 1000 and foo.capacity() is also 1000. If I clear the vector with foo.clear(), the size() is now 0, but what is the capacity()? Does the standard say anything about that?
Alan Turing
  • 11,403
  • 14
  • 66
  • 114
28
votes
5 answers

Why does std::vector reserve not "double" its capacity, while resize does?

I just found out that std::vector::resize "doubles" its capacity even when resizing to one element above the current size: std::vector v(50); v.resize(51); std::cout << v.capacity() << std::endl; This program outputs 100 with GCC and Clang,…
Daniel Langr
  • 18,256
  • 1
  • 39
  • 74
26
votes
5 answers

Java StringBuilder(StringBuffer)'s ensureCapacity(): Why is it doubled and incremented by 2?

I have searched about this, but I couldn't find why StringBuilder's ensureCapacity() method won't lengthen the old capacity by just doubling but also adding two. So, when default capacity of 16 is full, next lengthened value will be 34 unless whole…
Philip Paek
  • 271
  • 2
  • 6
26
votes
2 answers

NSMutableArray initWithCapacity nuances

Does anyone have advice on how to best initialize an NSMutableArray when it comes to dictating the capacity? The documentation mentions that "...even though you specify a size when you create an array, the specified size is regarded as a “hint”;…
Joey
  • 7,457
  • 12
  • 50
  • 103
20
votes
2 answers

Why is this slower when giving ArrayList an initial capacity?

For an experiment, I made this little program. It just generates 10 million random strings and adds them to an arraylist. Notice that the arraylist does not have an initial capacity. // editors note: added the necessary boilerplate to run, // and…
Andrio
  • 1,243
  • 16
  • 35
18
votes
2 answers

Is it possible to give a python dict an initial capacity (and is it useful)

I am filling a python dict with around 10,000,000 items. My understanding of dict (or hashtables) is that when too much elements get in them, the need to resize, an operation that cost quite some time. Is there a way to say to a python dict that you…
Peter Smit
  • 24,538
  • 27
  • 105
  • 165
16
votes
8 answers

StringBuilder capacity()

I noticed that the capacity method returns StringBuilder capacity without a logic way ... sometime its value is equals to the string length other time it's greater... is there an equation for know which is its logic?
xdevel2000
  • 19,270
  • 35
  • 120
  • 188
14
votes
5 answers

std::vector capacity after copying

Does vector::operator= change vector capacity? If so, how? Does vector's copy constructor copy capacity? I looked through documentation but could not find a specific answer. Is it implementation dependent?
Anycorn
  • 46,748
  • 41
  • 153
  • 250
14
votes
4 answers

Why is the maximum capacity of a Java HashMap 1<<30 and not 1<<31?

Why is the maximum capacity of a Java HashMap 1<<30 and not 1<<31, even though the max value of an int is 231-1? The maximum capacity is initialized as static final int MAXIMUM_CAPACITY = 1 << 30;
tesnik03
  • 1,226
  • 2
  • 11
  • 22
1
2 3
15 16