The Big Programming Thread - Page 298
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
![]()
BisuDagger
Bisutopia19158 Posts
| ||
RoyGBiv_13
United States1275 Posts
On May 10 2013 09:18 berated- wrote: You need to move the double[] creation to within the for loop. Even though you are putting new values in the array, you are putting the same array into each entry into the map. Yep, thats precisely correct. If you read it in its current form, there is only one call to "new double[2]" for the entire map, meaning that there is only memory allocated for one of these double[2] objects in the heap. By adding the line "x = new double[2]" to within the for loop, you are allocating N double[2] objects, so they won't all be the same reference. When x is assigned to a new object, since the old object is still referenced within the Map, the garbage collection won't be picking it up. + Show Spoiler + Your dataset isn't too large, but if this code is taking too long, then you can try to optimize it by allocating a very large piece of the heap near the start of the function, then chopping it up and giving the map sequential 16 byte values from that allocated memory. I don't remember a good way to do that in Java.... | ||
Abductedonut
United States324 Posts
On May 10 2013 07:47 thOr6136 wrote: Hey, i have a problem. So, java. Summing up a task first: 300 txt files with dates and temperatures over 10 years. I have to read all the temperatures and add them into maps with different kind of keys, for value we use List<Double> for storing temperatures. So basically we have to make 4 kind of maps with different kind of keys. One key is Location (name of file) other one is Location + year etc. After that we have to make another set of maps - keys equivalent to the ones before only values have to be different. This time we need double array (List before) with 2 values in it, one is an average value of all temperatures in that list (from map from before). Now here i have a problem. I use a method for generating a new HashMap with same keys as before but different kind of values (double arrays). The problem is, when i add keys to the new map i am creating (i use put(key, value)) it overwrites values from before but the key is completely different. It shouldn't happen because put method always compares 2 keys with equals() method and it compares hashCode(). When i debug the key that i input in put method is always different, but values get overwritten each time. It's so strange... Anyway i can post a code of this part:
Is there anything that could make overwriting all the values from before in map? Or am i missing something in this part? This has nothing to do with your problem, but parsing the files part sounds like a job for grep -r with some regex's. All you'd have to do is pipe its output to java. Not sure if that's possible. Anyway, just an idea! | ||
Shield
Bulgaria4824 Posts
A. Cached pool like - http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool() (you re-use threads) B. Worker/dispatcher threads C. Fixed thread pool like - http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool(int) D. Other (specify please) I guess it depends on the application, e.g. you may want worker/dispatcher threads for servers, while cached pool could work for desktop & servers. | ||
RoyGBiv_13
United States1275 Posts
On May 11 2013 04:47 darkness wrote: I'm curious what the most useful/efficient approach is when it comes to using threads. A. Cached pool like - http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool() (you re-use threads) B. Worker/dispatcher threads C. Fixed thread pool like - http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool(int) D. Other (specify please) I guess it depends on the application, e.g. you may want worker/dispatcher threads for servers, while cached pool could work for desktop & servers. This is a totally OS and application dependent question. If you want to PM me some specifics, I can lay down the knowledge. | ||
icystorage
Jollibee19343 Posts
| ||
Shield
Bulgaria4824 Posts
On May 11 2013 06:18 RoyGBiv_13 wrote: This is a totally OS and application dependent question. If you want to PM me some specifics, I can lay down the knowledge. I was asking in general, but if you feel like you want to explain, then I'd be happy to read. | ||
RoyGBiv_13
United States1275 Posts
They say you don't really know a subject until you can teach it... | ||
Release
United States4397 Posts
| ||
icystorage
Jollibee19343 Posts
a bad analogy that i can think of is that anybody can shoot a ball to a hoop but not all can play basketball (or in the nba?) Lol terrible | ||
fabiano
Brazil4644 Posts
On May 11 2013 11:18 Release wrote: In light of recent discussion in this thread, is a computer science bachelor degree worth pursuing if I'm interested in programming in the future? Or should I major in something else (finance/engineering for example) and program on my own time? You should major at something you like... | ||
snakeeyez
United States1231 Posts
When I get home from programming all day the last thing I want to do is sit at a computer anymore let alone think or program something. The thing is though I still have stuff I want to do on my computer or do things I want to do that I cant do the whole day at work. It can be rough sometimes. | ||
phar
United States1080 Posts
![]() * other components here would be: a job that you're good at, and a job that has some market. Simply liking it isn't sufficient. | ||
GunSec
1095 Posts
import random def snookerGame(): colored_Balls = [('Yellow',1),('Green',1),('Brown',1),('Blue',1),('Pink',1),('Black',1)] potted = [val for val, potted in colored_Balls for i in range(potted)] print(random.choice(potted)) I got my inspiration here in the end of the page: http://docs.python.org/3/library/random.html | ||
GunSec
1095 Posts
![]() | ||
bangsholt
Denmark138 Posts
| ||
phar
United States1080 Posts
On May 12 2013 04:42 GunSec wrote: btw, I am also wondering if I can pm some of the moderators of this thread or the creator? I have some personal stuff I want to talk about in programming and computer science in general ![]() Don't think many mods or the creator post here often... Many here could probably field answers, but it's hard to say exactly without knowing what your line of questioning is about. | ||
GunSec
1095 Posts
On May 12 2013 05:20 phar wrote: Don't think many mods or the creator post here often... Many here could probably field answers, but it's hard to say exactly without knowing what your line of questioning is about. well do you know who of them are responding to pm's or maybe I should try to pm all of them? I was just going to ask a few questions about computer science education and some personals problems about failing in programming etc. | ||
phar
United States1080 Posts
| ||
CatNzHat
United States1599 Posts
On May 12 2013 04:49 bangsholt wrote: Suppose you have read this python doc, so yes, it should be random. Just remember that we in general are very bad at understanding random. For the purposes of the game, python random will work fine. It's not like SecureRandom in Java, if you want to learn more about random number generators and their various levels of security (how random they actually are, what they use for seeds, etc..) then ask away. | ||
| ||