memory-efficient

Simple Java Program Increasingly Consuming Memory

Deadly 提交于 2019-12-23 16:43:32
问题 I have this simple Java Code which creates a single JFrame instance and displays it. This link contains the screenshot of memory consumption graph taken by jconsole What worries me is that java.exe in task manager shows memory usage continuously increasing at the rate of 4-5 kbs every 8-9 seconds. Need help import javax.swing.*; class MyGUI extends JFrame { public void makeGUI() { setLayout(null); setSize(500, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } } public

What is the fastest way to find integer square root using bit shifts?

只愿长相守 提交于 2019-12-23 09:01:14
问题 I was looking for the fastest method to calculate the square root(integer) of a number(integer). I came across this solution in wikipedia which finds the square root of a number(if its a perfect square) or the square root of its nearest lower perfect square (if the given number is not a perfect square: short isqrt(short num) { short res = 0; short bit = 1 << 14; // The second-to-top bit is set: 1L<<30 for long // "bit" starts at the highest power of four <= the argument. while (bit > num) bit

C++ check if item is in a array [duplicate]

☆樱花仙子☆ 提交于 2019-12-22 19:41:22
问题 This question already has answers here : Check if element found in array c++ (8 answers) Closed 8 days ago . In c++ I have an array and I am trying to check if there is a certain element in the array. Here is my array: string choices[3] = {"a", "b", "c"} I want it so that it prints out true if the user input is present in the array so if the user enters "b" then it will print true and give me the array index. This is like the Python version of in or find. I know I can just use a for loop to

C++ check if item is in a array [duplicate]

☆樱花仙子☆ 提交于 2019-12-22 19:41:04
问题 This question already has answers here : Check if element found in array c++ (8 answers) Closed 8 days ago . In c++ I have an array and I am trying to check if there is a certain element in the array. Here is my array: string choices[3] = {"a", "b", "c"} I want it so that it prints out true if the user input is present in the array so if the user enters "b" then it will print true and give me the array index. This is like the Python version of in or find. I know I can just use a for loop to

Iterators in Python 3

ε祈祈猫儿з 提交于 2019-12-22 09:29:45
问题 In Python 3 a lot of functions (now classes) that returned lists now return iterables, the most popular example being range . In this case range was made an iterable in Python 3 to improve performance, and memory efficiency (since you don't have to build a list anymore). Other "new" iterables are map , enumerate , zip and the output of the dictionary operations dict.keys() , dict.values() and dict.items() . (There are probably more, but I don't know them). Some of them ( enumerate and map )

Python: Memory cost of importing a module

跟風遠走 提交于 2019-12-22 08:29:10
问题 The memory cost obviously depends on exactly how large a module is, but I'm only looking for a general answer: Is it generally expensive or cheap to import a module in Python? If I have a few tens of small scripts that potentially stay in memory for the whole duration of the application, how much will that hog the memory? 回答1: It sounds like you aren't worried about time cost (good; that would be silly, since modules are only imported once) but memory cost. I put it to you: if you need all

what's more efficient? to empty an object or create a new one?

感情迁移 提交于 2019-12-20 12:28:40
问题 how expensive is 'new'? I mean, should I aim at reusing the same object or if the object is 'out of scope' it's the same as emptying it? example, say a method creates a list: List<Integer> list = new ArrayList<Integer>(); at the end of the method the list is no longer in use - does it mean that there's no memory allocated to it anymore or does it mean that there's a null pointer to it (since it was 'created'). Alternately, I can send a 'list' to the method and empty it at the end of the

Memory efficient multivaluemap

本秂侑毒 提交于 2019-12-18 06:12:11
问题 Hi I have the following problem: I'm storing strings and a corresponding list of integer values in an MultiValueMap<String, Integer> I'm storing about 13 000 000 million strings and one string can have up to 500 or more values. For every single value i will have random access on the Map. So worst case are 13 000 000* 500 put calls. Now the speed of the map is good but the memory overhead gets quite high. A MultiValueMap<String, Integer> is nothing else then a HashMap/TreeMap<String,

Is there a way to paste together the elements of a vector in R without using a loop?

偶尔善良 提交于 2019-12-17 15:46:42
问题 Say there's a vector x: x <- c("a", " ", "b") and I want to quickly turn this into a single string "a b". Is there a way to do this without a loop? I know with a loop I could do this: y <- "" for (i in 1:3){ paste(y, x[i], sep = "") } > y [1] "a b" but I will need to do this over many, many iterations, and having to loop over this and replace the original with the new each time would become very time consuming. I always want to be able to do something like this: x <- paste(x) as if paste()

Python - dividing a list-of-lists to groups

丶灬走出姿态 提交于 2019-12-13 16:54:14
问题 Consider the following simplified case: lol = [['John','Polak',5,3,7,9], ['John','Polak',7,9,2,3], ['Mark','Eden' ,0,3,3,1], ['Mark','Eden' ,5,1,2,9]] What would be a pythonic and memory+speed efficient way to transform this list-of-lists to a list-of-lists-of-lists based on the first two parameters: lolol = [[['John','Polak',5,3,7,9], ['John','Polak',7,9,2,3]], [['Mark','Eden' ,0,3,3,1], ['Mark','Eden' ,5,1,2,9]]] Actually - any other data structure would also be ok, as long as I have the