« first day (3497 days earlier)      last day (1536 days later) » 

7:28 AM
Ive tried to use smart pointers but it feels so weird to me . Is it bad? I would rather work with raw pointers.
@trollingchar thanks i just used joints
 
the thing of smart pointers is that they free memory when going out of scope
 
yeah but i was working with raw pointers for so long that i d rather use them as much as possible
 
Thing *thing = new Thing();
when it goes out of scope it's a leak
and if you pass it somewhere you don't know to delete or not to delete
 
If it goes out of scope it will be destroyed by itself. No?
just a pointer
 
a pointer is allocated on stack so yes, but heap memory will not be freed
you have to write delete ptr to free it
 
7:37 AM
yes i know
 
 
1 hour later…
user92578
8:49 AM
@0x00004 Smart pointers are harder because you need to think about ownership properly, but that's the whole point. Otherwise you will be leaking memory, guaranteed. If you already now start writing code without any news or any deletes, you'll be much better off in the future. I do not really want to touch my old game's codebase anymore because it uses rawpointers, and its a nightmare to manage memory there.
 
user92578
Raw pointers are good for passing around nullable instances, or storing stuff in a class etc., but a raw pointer should never ever own memory
 
user92578
Banning new & delete is an easy way to guarantee that
 
9:15 AM
so in short i should never use "delete" and "new"?
 
user92578
yup
 
user92578
raw pointers are fine but not for ownership
 
user92578
std::observer_ptr might remove the need for those completely, but I can't manage to find a reference as to when/if that might get into the standard
 
10:20 AM
and just dont forget to null ptr in case i dont need them anymore?
 
why null pointer
 
user92578
what
 
i mean when i m done working with raw pointers
or there s no need to null them ?
 
when you assign null to raw pointer, nothing happens
you are not freeing any memory
 
yes i know
i guess if i use smart pointers there wont be need for that
 
10:29 AM
and there are no reference counting on raw pointer so assigning null does not decrement reference count
this is just not needed
 
user92578
I've always considered assigning null to pointers as a code smell, and yeah, its unnecessary with smart pointers
 
if you own the object then delete it else do nothing
 
user92578
No! Dont delete
 
user92578
Ban delete and new from your codebase
 
smart pointers take advantage of RAII and they-
I haven't finished!
I was going to say, with smart pointers you can avoid new/delete at all
 
10:33 AM
@trollingchar for example :
while(object){//do that}
and if you null that object that chunk of code wont process
wrong actually
i mean
 
do you really need a loop here?
 
i null raw pointers when i use something like *currentEnemy
 
nwp
@0x00004 I think I know what you mean and it's correct. some_unique_ptr = nullptr; is a way to say "Clean up whatever you're holding". It's rarely needed though.
 
so that i can use that pointer for several objects
 
user92578
Calling reset feels cleaner but might just be me
 
nwp
10:38 AM
If you use the pointer for another object why do you null it first?
 
here s an example from my code:
if (m_player)
		{
			m_player->update();
		}
and if i just write : player->update() the code will no longer work if that players gets removed
 
so
does "removed" means "destroyed and memory freed"?
 
not always
if i dont null m_player that code above wont work
 
I think you can also use return or break to prevent code from running
 
also if i remember well it prevents object from being deleted several times
@trollingchar i never tried. Maybe
 
11:10 AM
https://docs.unity3d.com/ScriptReference/Quaternion.Euler.html
It says : "Returns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis; applied in that order."

However (AFAIK) to do the same rotation in 3 separate steps you must do it in reverse order :
Quaternion q = qY * qX * qZ;
Why is it so ?

I have created a JSfiddle that illustrate this : https://jsfiddle.net/b19zg6ew/1/
 
:53683849 int *a = new int(5);
	int *ptr = a;
	delete ptr;

	if (ptr)
	{
		std::cout << a << std::endl;
	}
if(ptr) condition wont work here but it will if you null ptr
Sorry. If(ptr)condition will work here even though ptr and a were deleted. It wont work if you nullptr.
 
just remove that if block because the condition is always false
I have trouble understanding what you are trying to achieve
 
you mean in my code?
@trollingchar how come if condition works as long as poniter is valid?
pointer*
 
11:26 AM
you are probably using some other condition to decide if it should be deleted
why not to use it for other stuff related to this pointer
if (should_delete) {
    delete p;
}
else {
    p->whatever();
}
if (should_delete) {
    delete p;
    return;
}
p->whatever();
 
why bring another boolean variable if you can just null ptr to make object invalid
?
 
user92578
This whole conversation gets obsolete if you start using smart pointers or std::optional
 
@0x00004 it's the initial decision when the object is valid initially
Anyway, I don't like to mess with all this: maybe it's null and maybe not, and it may be deleted anywhere and may be not
You either want to use an object or to delete it, but not both
But you want both
 
11:44 AM
@trollingchar its not that way.
 
nwp
@trollingchar Bethesda would like to hire you.
 
12:05 PM
@trollingchar it can be used for example where you need to respawn player in case it dies so you update, draw it etc only as long as it lives
and in case it dies you respawn him
 
so it's just some kind of optional value
then it's probably ok, but not ok for me
and null pointer just serves as marker in your case
I remember my unfinished bullet hell on C#, there was the player variable too, and checked by some attacks/homing bullets
c# has garbage collector so I fortunately don't have to worry so much about memory ownership
but anyway, using null as some marker and assigning null before variable goes out of scope is two entirely different things
in your case, variable does not go out of scope
 
 
2 hours later…
2:47 PM
Hello!
 
Heya
 
Feels like the spring will be around soon!
This also means that it's going to smell dog poo for some time due to it thawing.
 
Feels similar here. I hope it's a slow, tapered thaw, as our flood forecast is a bit more concerning this year.
 
@Pikalek Ah, that must be a real annoyance to live with that :/
 
3:02 PM
It's better than it used to be. Prediction has gotten better, there's more mitigation in place, almost all of the most flood prone houses have been swapped to green spaces & it's happened recently enough that people don't brush it off as something that happened way back in the pioneering days. But it still puts a strain on things.
If we or up watershed areas get a lot of early spring rain, things will go poorly though.
 
Yeah, I wish you the best of luck with that :)
 
Thanks! Honestly, it seems preferable to the covid outbreaks; the devil you know & all that.
 
Yeah
 

« first day (3497 days earlier)      last day (1536 days later) »