Perl 6 - the future is here, just unevenly distributed

IRC log for #openframeworks, 2015-05-05

| Channels | #openframeworks index | Today | | Search | Google Search | Plain-Text | summary

All times shown according to UTC.

Time Nick Message
01:45 ar_tama joined #openframeworks
02:05 Kyle1 joined #openframeworks
03:01 BlueThen joined #openframeworks
03:14 ar_tama joined #openframeworks
03:33 jvcleave joined #openframeworks
03:36 jvcleave_ joined #openframeworks
03:48 ShrewdSpirit joined #openframeworks
03:51 jvcleave joined #openframeworks
04:39 TimedoutSpirit_ joined #openframeworks
05:01 ShrewdSpirit joined #openframeworks
05:02 notjosh joined #openframeworks
05:57 alski joined #openframeworks
07:21 mh_ joined #openframeworks
08:02 Pisuke joined #openframeworks
08:53 mh_ joined #openframeworks
09:48 mh_ joined #openframeworks
09:56 Beliq joined #openframeworks
10:01 mh_ joined #openframeworks
10:04 HarryHaaren joined #openframeworks
10:32 mh_ joined #openframeworks
11:08 mh_ joined #openframeworks
11:32 Beliq joined #openframeworks
11:47 mh_ joined #openframeworks
11:52 mh_ joined #openframeworks
11:56 HarryHaaren_ joined #openframeworks
12:08 HarryHaaren joined #openframeworks
12:32 _mh joined #openframeworks
13:13 mh_ joined #openframeworks
13:16 Pisuke joined #openframeworks
14:42 mh_ joined #openframeworks
14:46 mh_ joined #openframeworks
14:56 Kyle1 joined #openframeworks
14:58 mh_ joined #openframeworks
14:58 marcocanc joined #openframeworks
15:10 mh_ joined #openframeworks
15:33 alski joined #openframeworks
15:54 kylemcd joined #openframeworks
15:57 ofarturo joined #openframeworks
15:57 kylemcd hi :)
15:57 ofarturo hey
15:57 kylemcd in this case i think i can see that Verlet owns all the Particles
15:58 kylemcd so it should be allocating and destroying them, right?
15:58 ofarturo so if you use pointers for any particle system (any type of pointers) the memory will be allocated anywhere
15:58 kylemcd right...
15:58 ofarturo if you allocate a vector of objects everything will be contiguous in memory so will be cached and accessing it is way faster
15:58 kylemcd got it
15:58 kylemcd but what if i want to dynamically add particles?
15:59 kylemcd won’t the addresses change upon reallocating the vectors?
15:59 ofarturo you just add an object
15:59 kylemcd (then all the contraints will have the wrong pointers)
15:59 ofarturo you can use a list or call reserve at the beginning to a really big number
16:00 ofarturo also in c++11 emplace_back instead of push_back avoids any copies when adding elements
16:00 kylemcd i saw a change to emplace_back for ofFile and was curious about that
16:01 kylemcd hmm
16:01 ofarturo also shared_ptr needs to increment an atomic counter every time you make a copy of it which is not super heavy but for smaller objects like particles it might be too much
16:01 ofarturo vector<ofVec2f> vectors;
16:01 kylemcd i really don’t like the idea of a maximum number of elements, do you think there is any way around that while keeping good caching?
16:01 ofarturo vectors.emplace_back(x,y)
16:02 kylemcd that’s so cool
16:02 ofarturo a list of particles is already better than a vector of shared_ptr but no if you want contiguous memory a vector or array is the only way
16:02 marcocanc joined #openframeworks
16:03 kylemcd good to know
16:03 ofarturo also if you only allocate from time to time if should be fine if the vector reallocates at some point
16:03 ofarturo the internal size of the vector stays at the max it was allocated at any time even when you clear it so it won't reallocate until you arrive to that size again
16:04 kylemcd i think i read that before when trying to understand how stl manages memory… nice
16:05 ofarturo and for returning from functions just use references i don't think you need to hold a reference in all the code for longer than the scope of the function
16:05 ofarturo so shared_ptr don't make sense
16:06 kylemcd makes sense
16:07 kylemcd i was trying to multithread some of this code
16:07 kylemcd using grand central dispatch
16:07 kylemcd and i noticed some weird behavior when i used raw pointers
16:07 kylemcd gcd was trying to deallocate things for me that were not allocated inside the multithreaded code
16:08 kylemcd which caused crashes when multiple threads tried deallocating the same thing
16:09 kylemcd actually, sorry, it was with some other code:
16:09 kylemcd https://github.com/kylemcdonald/op​enFrameworksDemos/blob/master/Barn​esHut/src/ParticleSystem.h#L39-L51
16:09 kylemcd sorry about the indentation, xcode is crazy
16:10 kylemcd but initially, i used raw pointers inside Tree
16:10 kylemcd https://github.com/kylemcdonald/openFramewor​ksDemos/blob/master/BarnesHut/src/Tree.h#L14
16:10 kylemcd then i switched to shared_ptr and it worked
16:11 kylemcd i think gcd might make a copy of the object for each thread, then on the object destruction it was calling delete on the pointers
16:12 ofarturo i see, never used gcd, is mostly queues were you send tasks right?  that's really strange i guess it shouldn't deallocate anything like that but have never used it.
16:12 kylemcd yes, you can also use it like you would do open mp for easily parallelizing loops
16:12 kylemcd since openmp isn’t supported w clang anymore i’ve been using more often
16:16 kylemcd thanks for your advice :)
16:41 ofarturo joined #openframeworks
16:52 admsyn joined #openframeworks
16:54 pizthewiz joined #openframeworks
17:02 pizthewi_ joined #openframeworks
17:06 pizthewiz joined #openframeworks
17:10 pizthewi_ joined #openframeworks
17:15 marcocanc joined #openframeworks
17:37 pizthewiz joined #openframeworks
17:57 pizthewiz joined #openframeworks
18:11 pizthewi_ joined #openframeworks
18:16 alski joined #openframeworks
18:17 kylemcd joined #openframeworks
18:18 kylemcd ofarturo i just realized that besides adding new particles, i want to be able to delete old ones — so i think i need a list instead of a vector
18:21 pizthewi_ The `erase` method can remove one or more elements too no?
18:22 pizthewiz joined #openframeworks
18:23 kylemcd pizthewiz yes the erase+remove idiom is great but it will invalidate the pointers / move memory around
18:23 kylemcd which means any constraints that point to those particles are incorrect
18:23 alski joined #openframeworks
18:25 pizthewiz Hmm, maybe I'm not following the particular use, but if you have external references to a data structure containing objects and you remove one you'll have that problem no?
18:25 pizthewiz Er, external references to objects within the container
18:26 kylemcd right, there is a problem if the references are to elements in a vector — but lists don’t change the location of their elements on add or remove
18:26 pizthewiz I thought the real difference between std::vector and std::list had to do with usage patterns and complexity
18:27 kylemcd complexity is why i usually use one vs the other
18:27 pizthewiz A vector could hold pointers itself just like a list though no?
18:27 kylemcd but in this case i need certain guarantees about pointer invalidation
18:27 kylemcd it could, but i don’t want to store pointers, i want to store objects
18:27 kylemcd i’m trying to get them to be relatively close to each other in memory
18:28 kylemcd but still elegantly handle the case where things are added and removed
18:28 pizthewiz shared_ptr? ;0)
18:28 pizthewiz They can be a bit more friendly if you typedef them too
18:28 kylemcd :)
18:29 kylemcd shared_ptr has a similar problem with the memory being pretty chaotically allocated
18:29 kylemcd even if you sorted the elements by location, they’re still really scattered in memory
18:55 pizthewiz You are right, std::vector insert is by copy/move not reference, std::list insert is by reference?
18:57 marcocanc joined #openframeworks
19:04 alski joined #openframeworks
19:15 marcocanc joined #openframeworks
19:24 kylemcd joined #openframeworks
19:25 kylemcd :)
19:26 kylemcd ofarturo this looks great
19:29 w4ffles joined #openframeworks
19:37 kylemcd i changed it back so it looks the same by default, and doesn’t jump when you click+drag a constraint https://github.com/kylemcdonald/openFrameworksDemo​s/commit/d7f74ab6ea76ebfad708f2ec04e0836bfe7d2875
19:37 kylemcd i also don’t have nullptr yet for some reason
19:39 kylemcd this is the one i’m really trying to figure out https://github.com/kylemcdonald/openFra​meworksDemos/tree/master/BarnesHut/src
19:40 kylemcd i’m not sure how to set up a container that minimizes distance between elements to avoid cache problems, but still allows for adding and removing items dynamically
19:41 kylemcd a list would work, but i need a subscript operator to use GCD to parallelize the loops
19:42 marcocanc joined #openframeworks
19:42 kylemcd so i’m trying to use a list as the backing type but cache pointers in a vector
19:57 kylemcd ahh it’s too crazy i don’t think it’s possible. i’m just going to use shared_ptr and make sure to move it around with references to avoid copies.
20:21 notjosh joined #openframeworks
20:59 wjf_ joined #openframeworks
21:21 ofarturo joined #openframeworks
21:43 wjf_ joined #openframeworks

| Channels | #openframeworks index | Today | | Search | Google Search | Plain-Text | summary