Language: 
To browser these website, it's necessary to store cookies on your computer.
The cookies contain no personal information, they are required for program control.
  the storage of cookies while browsing this website, on Login and Register.

Author Topic:  picked up items from map keep old x/y attributes  (Read 125 times)

0 Members and 0 Guests are viewing this topic.

Dolfo

« on: 27, October 2022, 22:08:36 »
Before i forget this to report. I have noticed that when picking up items from ground, pickup code didn't remove the x and y attributes in this object. Could free "some" server memory and disk space.
Don't believe the shit, you hear in mainstream. Believe your own body. Your body is speaking always the true to you. But you need to understand your body. Hear to your body, not to your ego. And when body is calling to you: "Hey something is wrong!" find the reason(s) for that. Man in White don't go for that, they don't want to heal you. They want earn money and sell you medicine, you should take rest of your life. You are not the patient, you are their customer. Never forget this!

Dolfo

« Reply #1 on: 05, November 2022, 04:49:57 »
It's in insert_ob_in_ob in object.c
I nulled x and y here.
Code: [Select]
/* Sort out the revised object chain. */
m = op->map;    // if op was removed from a map op->map != NULL
op->map = NULL; // op->map must be nulled for merge_ob()
op->env = where;
op->above = op->below = NULL;
op->x = op->y = 0;

Behavior without x/y null, objects keep there old x/y data when picking them up, also after reloging x/y is still in object definitions. Didn't checked apartement, if objects in containers also still have their old x/y coordinates.

Behavior with x/y null, objects are clean, no more old x/y coordinates in picked up items, also after reloging old x/y definitions from before change picked up objects are cleaned. Didn't checked apartement.

Must test this change a little longer, but i think it has no downsides, only clean some data, free some memory, speed up some loops.

Edit: I think cleaning x/y coordinates to NULL this way is leading to memory leaks. Didn't read that deep, how objects are generated in server code. So we miss somewhere a kind of memory free command here.
« Last Edit: 05, November 2022, 17:40:03 by Dolfo »
Don't believe the shit, you hear in mainstream. Believe your own body. Your body is speaking always the true to you. But you need to understand your body. Hear to your body, not to your ego. And when body is calling to you: "Hey something is wrong!" find the reason(s) for that. Man in White don't go for that, they don't want to heal you. They want earn money and sell you medicine, you should take rest of your life. You are not the patient, you are their customer. Never forget this!

_people_

« Reply #2 on: 05, November 2022, 16:08:21 »
There's nothing dangerous about leaving x/y as stale. Any function which causes the object to no longer be inside an inventory will either set X/Y itself (e.g. dropping an item) or, in the case of remove_ob, marks the item for deletion. Because they're part of the object_t struct, you can't individually free that memory as it is part of the object_t. It's allocated until the entire object_t is freed (by the garbage collector).

x/y are integers rather than pointers, so setting them to NULL is illogical anyway. NULL is a void pointer to the 0x0 memory address. This means, in theory, setting X/Y to null should be safe (they'll end up 0) seeing them set to NULL may confuse the next person to pass through that area of code.
-- _people_ :)

Dolfo

« Reply #3 on: 05, November 2022, 16:28:15 »
But there must be a difference between 0 and null. I think when i use 0, this leads to x position 0? This didn't help me. I want to clean old x/y definitions from objects. We don't need the x/y position from an item, we picked up somewhere in past in our inventory or apartments. These old x/y informations will also be written to player files and apartment files and also read back from there. This is unnessary disk memory and processing time on read/write logics.
Don't believe the shit, you hear in mainstream. Believe your own body. Your body is speaking always the true to you. But you need to understand your body. Hear to your body, not to your ego. And when body is calling to you: "Hey something is wrong!" find the reason(s) for that. Man in White don't go for that, they don't want to heal you. They want earn money and sell you medicine, you should take rest of your life. You are not the patient, you are their customer. Never forget this!

_people_

« Reply #4 on: 05, November 2022, 16:57:21 »
The impact on disk IO here is negligible but it's probably fine if you set them to 0. However, don't set them to NULL - as I said, NULL is only a name for memory address 0x00. In fact, sizeof(NULL) is 8 on most architectures, while X/Y are 4-byte values. While C conveniently does the cast properly, using NULL here is harder to read than the equivalent, 0, because of the convention in C that only pointers can be NULL.
-- _people_ :)

Dolfo

« Reply #5 on: 05, November 2022, 17:39:44 »
Ok i have checked examine on items from different views (sa, player, debug player). Looks like x=0 is the trigger for no x output on sa examine and also for no write to filedata. So i use x=y=0 then. I personal like clean logics, don't like bugs, also the smallest bugs or unlogic behavior i must eleminate. That's my nature.

"First a few droplets fell, then it really started raining." If you don't care of a droplet, you can end later standing in rain.
Don't believe the shit, you hear in mainstream. Believe your own body. Your body is speaking always the true to you. But you need to understand your body. Hear to your body, not to your ego. And when body is calling to you: "Hey something is wrong!" find the reason(s) for that. Man in White don't go for that, they don't want to heal you. They want earn money and sell you medicine, you should take rest of your life. You are not the patient, you are their customer. Never forget this!

Dolfo

« Reply #6 on: 04, December 2022, 03:19:25 »
I have now a better understanding of what you meaned. But our "nice" and "clean" server code led me to this wrong view.
Code: [Select]
if (!pointer)
if (pointer == NULL)
if (pointer == 0)
These are all the same and can be used for both POINTER and VALUE. Currently i fight to understand some code for treasure list and they used things like:
Code: [Select]
if(!x)
to check for x=0, this is really ugly.

For a cleaner code syntax we better use.
Code: [Select]
if (!pointer)
if (pointer == NULL)
if (value == 0)
« Last Edit: 04, December 2022, 12:13:40 by Dolfo »
Don't believe the shit, you hear in mainstream. Believe your own body. Your body is speaking always the true to you. But you need to understand your body. Hear to your body, not to your ego. And when body is calling to you: "Hey something is wrong!" find the reason(s) for that. Man in White don't go for that, they don't want to heal you. They want earn money and sell you medicine, you should take rest of your life. You are not the patient, you are their customer. Never forget this!

Tags:
 

Related Topics

  Subject / Started by Replies Last post
4 Replies
869 Views
Last post 18, September 2006, 14:08:27
by Gecko
1 Replies
577 Views
Last post 02, November 2006, 17:22:25
by Gecko
7 Replies
1051 Views
Last post 23, November 2006, 20:53:14
by smacky
5 Replies
212159 Views
Last post 06, April 2008, 01:39:51
by ThePlaneskeeper
10 Replies
93279 Views
Last post 07, December 2008, 17:17:44
by longir