« first day (319 days earlier)      last day (2517 days later) » 

1:15 AM
how can I get the max value for each x and y and z of vector<cv::Point3f> xyzBuffer; ?
 
1:59 AM
-1
Q: Need help resolving the last few bugs caused from rewriting a dynamic memory allocator (originally in C) in the Game Maker Language

TheGreatDuckSo I have the following sequence of scripts in Game Maker meant to provide an analogue of C's malloc and free interfaces. They intend to have the same interface except since Game Maker has no direct access to virtual memory, they use an array as the heap space. The dynamic memory allocator itself...

I know it's not exactly c++, but anyone that can help would be greatly appreciated.
 
@TheGreatDuck tldr
 
@Mikhail that's rude
:p
 
@TheGreatDuck OT for this channel, OT for this site.
 
@TheGreatDuck: That question there should probably clearly state the actual issue at the start, rather than mention "last few bugs... somewhere in the several pages that follow".
 
@Arafangion Well I put them at the bottom.
 
2:02 AM
But yeah - this is C++.
@TheGreatDuck: The bottom isn't good enough!
 
@Arafangion I cannot tell you what the issue is without showing you the code first.
cause the question is why the code breaks when I reverse two lines of code that I should be able to reverse arbitrarily.
 
@TheGreatDuck: You're going ot have to figure that out, I'm afraid. SO people have very, very short attention spans.
 
13 messages moved from Lounge<C++>
 
@TheGreatDuck: That's a FANTASTIC thing to mention at the top!
 
2:04 AM
@Mysticial dude. This isn't even a c++ question.
I was mostly asking for feedback on the question...
 
@Aaron3468 Thats a bullshit question, and I'm voting to close because I don't know what the guy is asking. Also the post has no question marks.
 
@TheGreatDuck It was long and unclear. You said there were bugs, then you said there weren't. It uses a program that has only a marginal relation to C++, and you're reinventing the wheel.
And the messages were moved to a place where people go to answer deeper questions like that. You'll get better help from that room.
 
@Aaron3468 this is the only chat that's here that has anyone in it at the moment, and what do you mean 'reinventing the wheel'
 
@TheGreatDuck Reinventing the Wheel - retrieved via Google search engine, May the 25th
 
@Aaron3468 That is not what I meant and you know it.
what are you referring to in my post that is reinventing the wheel?
 
2:11 AM
You're remaking malloc and free. Do you want to write your own game engine? Game engines provide scripting languages so that you don't need to deal with low level stuff like that.
 
"Note that the assignment of the instances to the instance id's changes every step so you cannot use values from previous steps. Also please note that instances that are deleted will remain in the list until the end of the step. So if you are also deleting instances you need to check whether the instance still exists. Let me give an example. Assume each unit in your game has a particular power and you want to locate the strongest one, you could use the following code: "
 
Basically it's a shitty language in a shitty environment.
 
^^that basically states that "we have pointers but they routinely shuffle"
 
But that's the challenge he has.
 
easier to implement a heap (for me) then to implement a game loop, graphics engine, collision detection, and all the other stuff I get for free.
plus, this particular project has been in the works for a while. I just hadn't gotten to the bits requiring data structures of that sort yet.
I mean, if the pointers weren't broken, I'd just use GM's own objects. :p
 
2:15 AM
@TheGreatDuck: There are a huge number of other game environments.
@TheGreatDuck: Eg, Love.
 
@TheGreatDuck Generate a unique name for each instance. Then use a traversal to find the instance by name, not id. Easier solution, especially if you have <1000 instances per level/scene.
 
@Aaron3468 that's idiotic and why are you trying to tell me to do something else when I already have a working solution. This is just a question about why a particular phenomenon (that is not giving me any noticeable bugs) occurs. It's literally just a question of curiosity. That's it. Why should it matter that it's supposedly reinventing the wheel and whatnot. I've improved the formatting. Since when did Stack Exchance censor based purely on content?
@Aaron3468 objects have names as in the actual resource name. Dynamically creating resources like that on the fly is just going to use up way too much memory and be incredibly slow, especially when I'm just trying to create small things like lists and tress which probably shouldn't use an object with physical properties as their components anyways.
 
Never said I was censoring you. You asked for feedback. I gave it. The question that's not a question has validity, though I feel a different approach would expose you to less bugs.
 
fair enough
 
But at this point, let's take this to the other room or please open a chat room with me.
 
2:21 AM
let's move over there then
:p
I didn't realize you were just giving feedback. I thought you meant the question was going to be closed as off topic. Hard to tell what people mean in these chats sometimes.
@Aaron3468 hello
in case it wasn't quite clear, I'm not actually getting any bugs when the code is in the order I have it right now. It's like there's a defect in the interface of my subfunctions that doesn't actually hurt anything so long as I play by different rules regarding it.
 
32 messages moved from Lounge<C++>
 
Hey, so yeah, that's part of why it's best not to react much to chatrooms. It's easy to fill in the blanks with "They're attacking me", even when it's not the case
 
yup
same happens in the reverse all the time
XD
 
At first glance, it appears the issue is that getNext(argument[0]) is returning either a null, or a really high value.
 
Anyway, for what I have in mind in particular, the low level structs shouldn't be much of an issue. I'm fairly proficient in C, so that sort of code is very familiar to me. The alternative difficulty and increase in man-hours of redoing everything else is far more costly than having to indulge in the (fun) exercise of writing some low level C code for a few data structures.
@Aaron3468 well bear in mind though that there is no "null" here. These are all array indices. But I see your point. :/
insert is what I have my eyes on though. The only time it gets called is at the end of that particular test when a node tries to get inserted between the head and the second block.
 
2:33 AM
And a very probable cause is that you're modifying an array as you iterate through it. Double check that you decrement the read pointer only when an object before it is removed, and increment it only when an object before it is added. It may help to draw a block diagram and step through your code
 
the read pointer?
 
The current address that you are at. In your code it seems to be freeP
 
ah
I can actually view the array's contents in the debugger I linked at the bottom
it prints a list of all the numeric values
and has two buttons that each call malloc and free with whatever i type in a popup box
@Aaron3468 to be a bit more specific, no, it doesn't appear to alter anything as it iterates normally other than the alteration of the links when new things are allocated. Strangely, enough, the version with set free after insert works perfectly. It's like insert is somehow falsely assuming that the free value is 0 without actually checking first.
:/
yet, nothing seems dependent on that being 0.
 
What does getLength(freeP) mean when freeP = HEAD_NODE = 0? How does getLength convert a value into an object with length? Just by counting from that index until an empty value is found?
 
freeP is the index of the array
getLength parses the value at that spot and gets the length of the supposed memory block that follows
by zeroing out the 32'nd bit of the integer
(it's universally assumed that nothing that large will ever be allocated as it would violate the array max length)
head node is just the index of the first piece of block padding
to be fair, I probably could optimize that away by replacing with zero but that would probably harm readability.
@Aaron3468 I hate to ditch out on you, but I have to go for a bit. Maybe we talk later if you see anything?
:-)
 
2:57 AM
@TheGreatDuck if (getLength(freeP) - newsize > 0 && !getFree(freeP))
At this point, freeP is always == HEAD_NODE
 
3:12 AM
So when you get the length, it always says that there is more room for allocating if freeP has been set to false. When you call setFree(freeP, true), you set the available space to getLength(freeP) + true << 31. This sets it to the heap's max size + the address size.
Basically toggling the state of getFree. So if you set it free before you malloc, you change the result of the check && !getFree(freeP) and cause your program to allocate improperly
 
@Aaron3468 I added getLength in. Didn't know it was missing.
freeing data is supposed to occur before you reallocate
 
What happens if you change it to && getFree(freeP)? Does that allow you to setFree before you insert?
 
then I'll try to allocate memory within blocks that are not free
and I'll end up doubly allocating the same memory
(really bad idea to do that)
the first stuff before p = tail_node is basically an iteration through the list of blocks looking for deallocated blocks
free means "it has been deallocated by a call to free"
weirdly enough, returning true means it isnt free but thats by design not accident
bad choice of name i suppose
 
bool TCs(Graf *G, int sin, int sfm, List *LV, int *c_c, List **LFP, List **LFM)
if (*c_c <= (*LFM)->c_a)
LV->c_a = *c_c;
*LFM = LV;
 
@Trusthefllow what is that? :-)
 
3:28 AM
Calling the function: tcs(..., &LFP,&LFM...)
I cant seem to be changing the pointer to LFP and LFM because when I print them they appear as (0) (0) but if I print LV it prints the List ok
I think The problem Is when I try to change the pointer inside TCs
 
sorry but I don't enough details to say anything about it. :-)
 
Can we do like a private chat ?
 
nah
i probably wouldn't be able to help you. I'm not real good with objects in c++
 
Meh =) ^^
Thank you though :P
 
@TheGreatDuck Yeah, I understand that. This level of prolonged detail-oriented thinking is burning me out though, especially when it's code I haven't written before. Building mental models, especially with the detail required for debugging, is pretty draining.
 
3:30 AM
fair enough. That's why I included the visualizer. :-)
let's one see exactly what happens
or well...
for the most part :p
 
As I say, this seems a bit elaborate for a problem space that can be brute forced.
 
@Aaron3468 I already had the C version from 2 years ago for a class project I did so (since we're allowed to use our own code for future stuff) it was somewhat trivial to convery
ironically, this bug exists in the C version
in fact, there is no setfree in the iterative loop
 
I would look closely at how insert and setFree modify the global state they share. Clearly setFree voids the expectations that insert has in such a way that insert tries to allocate to space outside of the array
 
so everything just repeatedly allocates over the same blocks in the C version
@Aaron3468 yeah, it probably isn't setting the free bit to 0 when examining the data. After all 2^31 is a pretty big number.
brb
 
But because it's a shared state bug, everything bubbles out into malloc :)
Shared state is a terrible thing to do, and should be avoided at all costs.
@Trusthefllow This room

C

C stands for Control.
 
3:40 AM
@Aaron3468 shared state? I'm confused what you mean by shared state. Are you referring to the free value and the length of the allocated block being stored in the same index?
@Aaron3468 the functions are all meant to be similar to operations upon a linked list, so perhaps there's something I'm missing in terms of what you mean by shared state? The whole heap is a data structure, so it is natural that operations upon it cause side effects.
 
I'm referring to variables that exist outside of the scope. For example, all the functions modify HEAD_NODE, hence it is 'shared state information'. When one function changes it, the function must be very careful to be hygienic and set the state in a way that won't cause bugs in the other functions.
 
oh
that shouldn't ever change
 
The hardest bugs to discover in any program or system are those which involve shared state. This is because shared state bugs tend to 'bubble' outside of the culprit's scope
 
in fact, HEAD_NODE itself is pretty much a macro at this point (it's not but it doesn't change. It's always 0)
 
So a completely unrelated part tends to trigger it. Like a landmine ^^;
 
3:46 AM
if something is changing the head node let me know. That's not supposed to happen.
@Aaron3468 hence, I have a bug that doesn't actually exist when i reorder things. It's like the windows OS interface for pipes. Have to do a little dance to get everything to work right.
(If you've ever used the C windows pipeline interface, you'll know what I mean)
If not for the absurdity of such a claim, I'd swear each pipe or handle goes on a stack and the whole blows up if the function calls aren't modifying the guy on the top of this invisible stack. Good for enforcing good code organization, but frankly... it's kinda stupid.
:p
not exactly shared state but it is a landmine of sorts
on an unrelated note though I did just find a legit bug
in the insert function I claim nodes are aligned to 2 index sizes
 
The best solution to shared state is to pass state as an argument. It makes it easier to reason about the execution flow and who modified the state last.
 
i forgot to readd the code to adjust block sizes
except in this case, the state is the 'virtual memory' underneath
I'm gonna go test with the proper block sizes
chances are it's irrelevant but from what i remember my code was sitting on pins and needles when I built it
in fact, I've found quite a few bugs with my debugger. So, if anything my attempts to stabilize it a bit actually unveiled other problems.
 
@TheGreatDuck Yeah, I admit it's a bit harder when you program at such a low level. Really important to have very explicit and well-tested validation code.
 
the original project had validation code
somehow it passed with flying colors
yet, the same algorithm has blatant holes in it clearly visible by just printing out the memory contents
honestly, I almost wish I thought of this in C two years ago
would've probably been easier back then. :p
(cause y'know. old code and all)
 
@TheGreatDuck There you go. No bug, just a bit of responsibility was shifted to a different function than normally.
 
3:56 AM
Howdy :)
 
you found it?
 
C is a pretty messy language. That's why C++ and type checking came in.
 
actually c++ would've suffered the same fate
type checking wasn't the issue
it was just bad design in the algorithms themselves that I was using in my project
 
@TheGreatDuck No no, your code validates and functions with no bugs. But when your flow matches the textbook version, the bug appears. Hence one of the two functions is doing something the other is supposed to do.
 
honestly surprised in hindsight that the thing passed the tests. :/
actually, there was no textbook version
I wrote this from scratch back then
the only thing the book had was diagrams of memory
the project was to write all of them from scratch and there was master program it sat within that verified different aspects of it
 
3:59 AM
Okay. But you say you should free before you insert. And when you make the change to do this, it causes a bug. The idea of should is your attempt to follow some textbook or article somewhere
 
actually, I put free there cause it made sense to me
the should isn't so much a fact that it needs to so much as it the order shouldn't matter based on my design. In other words, the fact that order matters contradicts my own interface.
 
facepalm so you build a working program, and expect it to work the same if you pull one of the pieces out and put it in another place? In some situations, especially those with shared state, it's impossible to hold that contract.
To overcome these situations, you create a 'conventional order' and stick to it.
 
you misunderstand
think of it this way
if I have a list, and set one of the elements to a particular value, should it ever matter whether I do that before or after I add a new element after that?
I mean, I don't think anything cares about that afaik. I'd hope not. That's a weird condition to impose. :p
and to be fair, I wrote that there the first time thinking it would be right and then it failed. That was just a band-aid I slapped on it to try and fix it. For all I know, there are still other things not quite right with it.
ok
same error
block alignment had nothing to do with it
(which I suppose makes sense)
 
Well like I could expect code to function properly if I switch foo(34, True) with foo(True, 34), but that won't mean it does. The problem is an implied relationship to the argument order. Same thing with your code. Something you do in setFree depends on something insert does first, and if it doesn't happen, your list gives values outside of its size.
 
actually it's the other way around
setfree is ok
but it seems like passing a node with the free bit set to 1 blows up insertion
like it thinks that 1 is part of the length
 
4:12 AM
Sounds like you forget to mask the size somewhere
So that it ignores that bit
 
probably
considering I never even set the bit to 1 in the original version (and let blocks allocate on top of each other), that's a pretty high likelihood.
just as a sanity check
"HEAP_SPACE[argument[0]] & (~(1 << 31))" does in fact 0 out the leftmost bit correct?
 
HEAP_SPACE[argument[0]] & (~(1 << 31)) // returns the leftmost bit zeroed
HEAP_SPACE[argument[0]] &= (~(1 << 31)) // sets the leftmost bit zeroed
 
i found the damn error
from getFree
"return (HEAP_SPACE[argument[0]] & (1 << 31));"
^^please tell me that doesn't return either 0 or 1
 
yay bitwise
 
set length takes that value and shifts it another 31 bits
I need to add in a "> 0" XD
 
4:22 AM
@TheGreatDuck Returns 0 or the max value
 
yeah
and then in set length if you look at it... you'll see it takes that and tries to shift it even further
the test was a success this time
no more blowing up
 
Give it a shot, tell me if the error goes away. I was assuming that you meant to implicitly coerce an integer into a boolean ^^;
 
game maker doesn't do type coercion
in fact, it is typeless
 
Oh dear, even worse.
 
yeah
instead of set length getting "length + (1 << 31)" it got "length + (1 << 62)"
and of course, get length only filters the 32nd bit
so you get a really big number
 
4:24 AM
Btw, it may interest you to know there's a new version of gamemaker...
 
tbh, i thought game maker data types were 32 bit
I am aware of that, but due to conversion issues and a lack of a lot of features I prefer not to atm.
I don't tend to use the deprecated features in use however, they have a debugging tool that lets you execute GML at runtime for testing purposes
the new version got rid of it in all forms. pissed a lot of people off like me. Plus, more save file instabilities appeared
and routinely people "get shot by Mike Dailly"
which is another way of saying that the program randomly corrupted your entire game project
y'know. fun stuff ;-)
@Aaron3468 you want the honors of posting an answer or should I later?
 
No no, go ahead.
 
alrighty then.
0
A: Need help resolving the last few non-bug 'oddities' caused from rewriting a dynamic memory allocator (originally in C) in the Game Maker Language

TheGreatDuckThe issue lies within the subfunction getFree: getFree() { return (HEAP_SPACE[argument[0]] & (1 << 31)); } Unlike c which would ordinarily cast this to either 0 or 1 as being a boolean function, game maker is inherently typeless to an extent and so if the block is allocated (yes, the funct...

thanks
that was definitely hard to find
glad i found it though. It might've cropped up again later on if intuition serves right
plus, now my code is in a logical order. XD
(like it even mattered, but still... bugs are bugs)
I'll probably end up cutting away the 2 increment locking of blocks, but that can be done another day and i already know what to do for that
(the original project demanded 8 byte allignment and I just hadn't yet removed the code for the equivalent 2 index allignment)
@Aaron3468 another great advantage to this is that game maker objects come with a lot of built in junk. By using my own allocator for simple data structures, I'll save a shit ton of memory. Pardon my french.
 
5:09 AM
Well done. Yeah, rubber ducking is a good way to catch that stuff. It also helps if you have a type system checking if you're returning size, index/offset, or boolean.
 
 
8 hours later…
1:19 PM
What's the easiest way you can think of to allocate a matrix using the stl library in c++
?
 
are you planning to do arithmetic operations or sth? in that case use an actual linear algebra library like eigen, ublas or whatever OpenCV uses
 
no, no algebra
 
otherwise you'll be forced to reimplement everything, including multiplication and stuff
 
just a simple matrix to store values
I was thinking something like
 
Use std::vector and index with [x + width*y]
 
1:22 PM
std::vector<std::vector<int> > matr;
ah ok
that was my second thought
 
vectors of vectors approach is more annoying in general because you need to enforce that all inner vectors have the same size and it's waaay slower because of N+1 dynamic allocations instead of 1
 
stupid question
I don't know if you know the CLRS book
I'm thinking about implementing most of the algorithms
just for sake of practice with some problem I'm losing familiarity with
is that a good idea? or just a waste of time
?
in C++ of course
 
it's fairly pointless
 
how so?
 
you'll be exercising a skill you won't use 99% of the time
I mean, if you're interested in this, I won't stop you
 
1:31 PM
XD
 
if you want to just learn how std::vector is implemented, you can just look at the source code
if it's implemented in the standard library of the language you're using, it's no use reimplementing it
 
nono just for matter of skills
but anyway...
 
4 mins ago, by milleniumbug
you'll be exercising a skill you won't use 99% of the time
I don't say it's not useful
I'm saying you can learn skills that are more useful first
 
like what?
 
problem decomposition, writing maintainable code, learning language idioms
 
1:40 PM
what do you suggest for learning such stuff
?
 
coding for money
you'll get familiar with everything from this list
 
 
4 hours later…
5:28 PM
In the book(Tour Of C++), it says,
double s2 = sqrt(2);         // call sqrt() with the argument double{2}
double s3 = sqrt("three");   // error: sqrt() requires an argument of type double            *The value of such compile-time checking and type conversion should not be underestimated.*
Is that point referring to derived class type class to base class type conversion, amidst polymorphism?
 
 
5 hours later…
user1593881
10:12 PM
What's the rationale behind the basic_string wording on cppreference?
 
user1593881
When it's std::string.
 
std::string is a typedef to std::basic_string<char>
 
user1593881
I see. I never bothered to look at the implementation of a string. Took it for granted.
 
there are some other typedefs, listed on the main page en.cppreference.com/w/cpp/string/basic_string
 
user1593881
Awesome. Thanks.
 

« first day (319 days earlier)      last day (2517 days later) »