Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 633 634 [635] 636 637 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 887561 times)

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9510 on: May 14, 2016, 10:47:19 am »

BTW shared pointers are especially slow if you pass by value. Always pass them as & or const&

http://stackoverflow.com/questions/3628081/shared-ptr-horrible-speed

^ an algorithm using shared pointers is 10 times slower than the same algorithm using normal pointers. But switching to pass-by-reference for the shared pointers cuts that to only 3 times slower.

You're still going to see significant slowdown by using shared pointers however - the algorithm switches from most of the time doing the actual algorithm to most of the time wrangling pointers unnecessarily.

Generally, my rule of thumb is to avoid things like shared pointers and do memory management myself. But I wrap that up in class/structs: That which calls new, must call delete. Use lightweight wrapper classes for your data structures that need dynamic memory, and avoid virtual functions most of the time.

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9511 on: May 14, 2016, 04:16:05 pm »

Hey could you please suggest me a more or less simple python 2d graphics library for drawing images and 2d primitives on the screen? The task is to write a program that illustrates how binary search tree rotation is performed. That is, I need to get a binary search tree displayed on the screen, two of them to be precise: one that is passed as input and this same tree having some of its nodes shifted due to performing a rotation. The problem is that it's going to take a good screen area to draw merely a single tree (and there must be two of them), so it'd be great to have a window that allows scrolling and (not so necessarily) zooming.
« Last Edit: May 14, 2016, 04:26:13 pm by RoguelikeRazuka »
Logged

monkey

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9512 on: May 14, 2016, 05:31:27 pm »

I've tried SceneObject&, but it caused issues with "hitobj = _objects[x];". The reason for all the shared pointers is to handle automatic deletion of objects, and because that's how the instructor had set up the classes.

You could do:
Code: [Select]
bool trace_ray(std::shared_ptr<Vector4> origin, std::shared_ptr<Vector4> dir, SceneObject*& hitobj) const
...
hitobj = _objects[x].get();
But yeah, rewrite it without using shared_ptrs, if you want as an exercise for yourself.

Another point against using shared_ptrs is that it is just a reference count, if you have cycles nothing will ever get deleted.
ie. ptrA -> ptrB -> ptrC -> ptrA

Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9513 on: May 14, 2016, 05:46:32 pm »

refcounts remind me of further BYOND dumbness. clearing a list by doing listvar = list() (e.g. putting a new list object in the var instead of recycling the old one) would fail to decrement the refcount, and cause a memory leak that persisted through server restarts. the objects sticking around also caused some other issues, such as our master controller (which, as the name implies, is in charge of making sure all the other game controllers tick) spontaneously exploding every other round.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9514 on: May 14, 2016, 05:49:45 pm »

That sounds bad.</understatement>
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

optimumtact

  • Bay Watcher
  • I even have sheep
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9515 on: May 14, 2016, 11:29:35 pm »

refcounts remind me of further BYOND dumbness. clearing a list by doing listvar = list() (e.g. putting a new list object in the var instead of recycling the old one) would fail to decrement the refcount, and cause a memory leak that persisted through server restarts. the objects sticking around also caused some other issues, such as our master controller (which, as the name implies, is in charge of making sure all the other game controllers tick) spontaneously exploding every other round.

Reminds me of a similar one we had where locating on a moveable atoms locs list caused memory corruption in the list structures.
http://www.byond.com/forum/?post=1852790

It caused all the global lists to eventually corrupt and stop acting like global lists and would kill the game servers after a random period of time, the worst part however is that it would just happen slowly over time, so more and more functionality in the game would start silently failing and spewing runtimes.

Ahh byond, truly a worthy game engine.
« Last Edit: May 14, 2016, 11:31:23 pm by optimumtact »
Logged
alternately, I could just take some LSD or something...

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9516 on: May 15, 2016, 02:05:39 am »

Byond is the reason that I only ever played SS13 once, despite having a blast that one time.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9517 on: May 15, 2016, 12:07:15 pm »

Why on earth isn't there an ArrayList constructor that takes an Object[] as an argument...
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9518 on: May 15, 2016, 01:08:37 pm »

Why on earth isn't there an ArrayList constructor that takes an Object[] as an argument...

But there is. https://msdn.microsoft.com/en-us/library/83h9yskw(v=vs.110).aspx

Logged
<Dakkan> There are human laws, and then there are laws of physics. I don't bike in the city because of the second.
Dwarf Fortress Map Archive

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9519 on: May 15, 2016, 01:10:45 pm »

Byond is the reason that I only ever played SS13 once, despite having a blast that one time.
Playing in BYOND isn't even that bad.

Coding in dreammaker isn't even that hard.

The language just does a lot of things, deep down, that really, really dont make any sense. You generally don't encounter them until you're doing weird shit, or your codebase is over 350k lines.

Got to keep in mind that BYOND was made somewhere in the early 90s as a MUD making engine, though, and that you could probably still run your shitty 1994 MUD that you made in BYOND version 53 on BYOND version 511. (extreme backwards compatability is part of what has made byond so rotten on the inside)
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9520 on: May 15, 2016, 01:22:41 pm »

Why on earth isn't there an ArrayList constructor that takes an Object[] as an argument...

But there is. https://msdn.microsoft.com/en-us/library/83h9yskw(v=vs.110).aspx
Java native.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9521 on: May 15, 2016, 01:32:46 pm »

Why on earth isn't there an ArrayList constructor that takes an Object[] as an argument...

But there is. https://msdn.microsoft.com/en-us/library/83h9yskw(v=vs.110).aspx
Java native.

I'm so sorry.

(if only youtube also included an 'end at' time, so I could tell it to cut off just before mustafar)
Logged
<Dakkan> There are human laws, and then there are laws of physics. I don't bike in the city because of the second.
Dwarf Fortress Map Archive

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9522 on: May 15, 2016, 03:49:56 pm »

Why on earth isn't there an ArrayList constructor that takes an Object[] as an argument...
You want this?
Code: [Select]
ArrayList list = new ArrayList<Object>(array);

Try this:
Code: [Select]
ArrayList list = new ArrayList<Object>();
Collections.addAll(list, array);

Or this, even better:
Code: [Select]
ArrayList list = new ArrayList<Object>(Arrays.asList(array));
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9523 on: May 15, 2016, 03:51:18 pm »

Yeah, I found the last one after some Googling, but...Y'know. Kinda weird.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

jaked122

  • Bay Watcher
  • [PREFSTRING:Lurker tendancies]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9524 on: May 15, 2016, 08:03:20 pm »


I'm so sorry.

(if only youtube also included an 'end at' time, so I could tell it to cut off just before mustafar)


Just think, there are people who have chosen to use that programming language knowing of other ones.



Pages: 1 ... 633 634 [635] 636 637 ... 796