Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Lysandus
Jun 21, 2010

Painless posted:

The way you describe it, your way of "fixing" things sounds like a coding horror in itself. Class A has a bug, so fix it by quietly removing 'final' and extending with a class that has the bug fixed?

It wasn't a bug in the sense that there was a flaw in ClassA. I just call everything in our issue tracker a bug.

Adbot
ADBOT LOVES YOU

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa

wwb posted:

Except that the homo who wrote MySql decided to try and get the EU to stop the deal because his database is a special snowflake that deserves to live.

We should loving nuke sweden.

Go ahead. Monty Widenius is Finnish, though. And his Special Snowflake is re-opensourced (well, sort of) under the name MariaDB.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Lysandus posted:

It wasn't a bug in the sense that there was a flaw in ClassA. I just call everything in our issue tracker a bug.

That still isn't a horror. He was probably too shy to ask you if he could remove the final keyword from the class.

Janitor Prime fucked around with this message at 18:25 on Jul 1, 2010

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

MEAT TREAT posted:

That still isn't a horror. He was probably to shy to ask you if he could remove the final keyword from the class.

In fact, the "help" probably made him think that he was expressly not allowed to modify it, only to subclass it.

Lysandus
Jun 21, 2010
Touché.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
Also, if all he did was copy ClassA into a new ClassB, removed the final keyword from ClassB and then subclassed it to ClassC, all you have to do is remove final from ClassA and change ClassC's parent class to ClassA, and you have solved the "horror". That is a far cry from some of the poo poo that people pull that takes days/weeks/months+ to untangle.

dark_panda
Oct 25, 2004

Further to that, the MySQL Gotchas list.

Granted, some (maybe a lot) of these problems might be fixed in more recent versions of MySQL but it's still horrifying. MySQL is a coding horror in and of itself and actively propagates coding horrors as it is used. No SEQUENCEs, no CURSORs outside of stored procs and triggers, schizophrenic features that sometimes work on certain table engines but not on others... MySQL drives me nuts like no other software can. Well, maybe PHP.

My favourite MySQL shite mis-features that upped my ire recently are its horrible and brain dead spatial extensions:

- All spatial operations act on minimum bounding rectangles only so good luck with anything that isn't a box or a point.

- Ridiculously incomplete: no built-in distance() or centroid() functions or anything of any real use for that matter.

- Contrast to its main competition in PostGIS... I've been using PostGIS for years and had to cope with MySQL's spatial nonsense recently for a small contract and it was a horrible experience.

sklnd
Nov 26, 2007

NOT A TRACTOR

dark_panda posted:

MySQL drives me nuts like no other software can. Well, maybe PHP.
Two great tastes that taste great together.

A very bad man
Mar 31, 2010

Kidane posted:

While I am paid to write Perl, I am by no means an expert. However, I'm of the opinion that there is nothing inherent to Perl which requires overly-concise code. My boss looked at some code I wrote and said "it's very straightforward" which I take as a compliment although I suspect many Perl programmers wouldn't. :) My code tends to look like this:

code:
my $parse_mail = Email::Simple -> new( $email );
my $sender = $parse_mail -> header( "From" );
my $jira_summary = $parse_mail -> header( "Subject" );
my $jira_description = $parse_mail -> body;
I know of the more Perl-like way to write that, I just don't care. Someone here described my Perl as "awkward" which may very well be accurate.

Try running your code through Perl critic

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

dark_panda posted:

Further to that, the MySQL Gotchas list.

Granted, some (maybe a lot) of these problems might be fixed in more recent versions of MySQL but it's still horrifying. MySQL is a coding horror in and of itself and actively propagates coding horrors as it is used.

I looked through that list and I would say the things on it fall into three categories.

  • Things that are fixed in the current version of MySQL. Example: "1.4. Case sensitivity in CHAR / VARCHAR fields". The guy makes no mention of character sets and collations here - I'll be charitable and assume he must be talking about a version of MySQL that had no character set/collation support, or poor support.
  • Things which are admittedly bad, but which are fixed by making sure MySQL is running in traditional mode. (You should always make sure it is running in traditional mode.) Example: truncation of overlong strings.
  • Things that apparently work contrary to how the author hoped they would, but which I don't see any problem with. Examples: all the waffling about inserting integers into ENUM columns (to me being able to use integers to specify an ENUM element by its index is handy), or the thing about division by zero resulting in NULL. N.B. this last is also different if MySQL is in traditional mode.

dark_panda posted:

schizophrenic features that sometimes work on certain table engines but not on others...

While I can see how that might be frustrating, I don't see how they could have implemented a flexible system for allowing swappable storage engines without having features that work on some engines but not others; and the swappable storage engines are nice to have. At any rate, most applications are fine sticking with InnoDB for just about anything, maybe MyISAM for text searching.

Can't comment on spatial data types, never used them. I have no reason to doubt what you say about them.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Why are swappable storage engines useful? On any other database I can make a table that does everything I want without worrying about that bullshit.

dark_panda
Oct 25, 2004

Hammerite posted:

I looked through that list and I would say the things on it fall into three categories.

  • Things that are fixed in the current version of MySQL. Example: "1.4. Case sensitivity in CHAR / VARCHAR fields". The guy makes no mention of character sets and collations here - I'll be charitable and assume he must be talking about a version of MySQL that had no character set/collation support, or poor support.-
  • Things which are admittedly bad, but which are fixed by making sure MySQL is running in traditional mode. (You should always make sure it is running in traditional mode.) Example: truncation of overlong strings.
  • Things that apparently work contrary to how the author hoped they would, but which I don't see any problem with. Examples: all the waffling about inserting integers into ENUM columns (to me being able to use integers to specify an ENUM element by its index is handy), or the thing about division by zero resulting in NULL. N.B. this last is also different if MySQL is in traditional mode.

The list itself is pretty old and flat-out says that it is referring to MySQL version 4.1 and below, so yeah, plenty of things are going to be fixed. My main problem is the attitude the problems represent in the first place, I think. The FOREIGN KEY stuff is just another example: the MySQL developers making up reasons for why you don't need a feature or why a feature is flat out wrong to begin with, despite said feature being rather fundamental to RDBMS design. To be fair, the FOREIGN KEY stuff has of course been long-fixed in MySQL up to a certain degree (don't even think about mixing table types if you actually want it to work), but that whole episode did leave a bad taste in my mouth.

As for some problems that can be solved by traditional mode, well, even those cases seem flat out weird. For instance, even with traditional mode enabled, "SELECT 1 / 0;" still returns NULL, 'cause apparently the ERROR_FOR_DIVISION_BY_ZERO option only errors out on INSERTs and UPDATEs; meanwhile, for SELECTs, a warning is silently produced. If MySQL were operating like a traditional RDBMS I'd expect errors for division by zero wherever they occur.

Further to that, why do they handle division by zero but not the square root of negative numbers or any other situation where the result of an expression is mathematically undefined? This works fine:

code:
mysql> insert into testing values (sqrt(-1));
Query OK, 1 row affected (0.04 sec)
Even with traditional mode enabled and all that. I'd expect that INSERT to error out as well, there doesn't seem to be an equivalent for ERROR_FOR_DIVISION_BY_ZERO for such undefined operations. MySQL's stance seems to be "when something is wrong, NULL is the answer." NULL isn't supposed to be some catch-all hand waving solution that solves all of life's problems in database management, it's supposed to represent that there is an absence of a value. In situations like this, we don't have an absence of a value but rather we know that the result of the expression is undefined mathematically, which is different than being absent.

Speaking of collation support, I find it bizarre that the default encoding and collation settings are latin1 and latin1_swedish_ci respectively. Collation is a bit harder to default, I guess, and I know MySQL AB is based in Sweden, but I would at least think that these days UTF-8 would be the more popular choice for the encoding.

Hammerite posted:

While I can see how that might be frustrating, I don't see how they could have implemented a flexible system for allowing swappable storage engines without having features that work on some engines but not others; and the swappable storage engines are nice to have. At any rate, most applications are fine sticking with InnoDB for just about anything, maybe MyISAM for text searching.

Can't comment on spatial data types, never used them. I have no reason to doubt what you say about them.

The swappable storage engines can be alluring, but in the end it seems to cause so many headaches that you start to wonder if it's worth it.

For instance, let's say you do want ACID compliance so you go with InnoDB. Meanwhile, you have a need for full-text search, as you say. Well, there goes your ACID compliance, 'cause MyISAM doesn't support ACID or FOREIGN KEYs.

Or let's say you want the spatial stuff I'm so interested in. Well, now you have a choice, 'cause both MyISAM and InnoDB support spatial columns, great. However, your choice involves either having ACID compliance or spatial indexes, 'cause only MyISAM supports indexes on spatial columns but only InnoDB supports ACID.

I realize that a lot of this is pretty subjective stuff and that MySQL does fill certain niches. It's just that for my uses, I have never thought to myself "I'd prefer to use MySQL over the available alternatives for this project." It's just littered with too many quirks and odd behaviours. Certainly, every database out there has its own set of quirks and oddities, but the sheer number of MySQL quirks and the attitude displayed in the past by its developers have biased me against it. Yeah, I'll admit that I'm flat out biased against MySQL, but it's not a bias without justification...

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

dark_panda posted:

Yeah, I'll admit that I'm flat out biased against MySQL, but it's not a bias without justification...

Thinking that a lovely piece of software or technology sucks because it is lovely is not a "bias".

blorpy
Jan 5, 2005

wwb posted:

Except that the homo who wrote MySql decided to try and get the EU to stop the deal because his database is a special snowflake that deserves to live.

We should loving nuke sweden.

The real horror here is that none of you called this guy on his homophobic bigotry. Shame on all of you.

Shumagorath
Jun 6, 2001

Markov Chain Chomp posted:

The real horror here is that none of you called this guy on his homophobic bigotry. Shame on all of you.
____________/

blorpy
Jan 5, 2005

Shumagorath posted:

____________/


Cool, an old gimmick and you didn't even get the nbsp right. Congratulations.

shrughes
Oct 11, 2008

(call/cc call/cc)

Markov Chain Chomp posted:

Cool, an old gimmick and you didn't even get the nbsp right. Congratulations.

                              \____________
                          

blorpy
Jan 5, 2005

shrughes posted:

                              \____________
                          

:golfclap:

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through

Markov Chain Chomp posted:

The real horror here is that none of you called this guy on his homophobic bigotry. Shame on all of you.

you're not a real computer person if you're not a horrible right wing bigot

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

Markov Chain Chomp posted:

The real horror here is that none of you called this guy on his homophobic bigotry. Shame on all of you.

If morons on the internet were ignored instead of engaged there would be fewer morons on the internet.

spiritual bypass
Feb 19, 2008

Grimey Drawer

MasterSlowPoke posted:

you're not a real computer person if you're not a horrible right wing bigot

You're not a real person if you're a computer person.

Nigglypuff
Nov 9, 2006


BUY ME BONESTORM
OR
GO TO HELL
Frankly I thought his homophobia was more or less cancelled out by his racism.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

MasterSlowPoke posted:

you're not a real computer person if you're not a horrible right wing bigot

There's a guy where I work (bay area, software company) who has a bunch of bumper stickers, like "some village in Kenya is missing its idiot" and "keep america pure, fight immigrants" and a bunch of other conservative drek

I don't what his job position is but I hope it's not management or customer support.

spiritual bypass
Feb 19, 2008

Grimey Drawer
He's probably a sysadmin and one day he'll probably bring a gun to work and start shooting people.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
:eng101: dreck

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

rt4 posted:

He's probably a sysadmin and one day he'll probably bring a gun to work and start shooting people.
That would fit (the sysadmins here are literally nazis)

Otto Skorzeny posted:

:eng101: dreck
http://www.merriam-webster.com/dictionary/drek

e: I guess the spelling depends on whether you're german or jewish

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

Nigglypuff posted:

Frankly I thought his homophobia was more or less cancelled out by his racism.

I'm not a fan of racism/xenophobia, but if MySQL and PHP had spawned from the same country you have to admit that there's a discussion about... "containment" that could at least take place.

blorpy
Jan 5, 2005

Come on guys, Lerdorf is Danish! Know your Scandinavian countries. :D

spiritual bypass
Feb 19, 2008

Grimey Drawer
I don't give a drat about any country that eats pickled fish :colbert:

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

dark_panda posted:

As for some problems that can be solved by traditional mode, well, even those cases seem flat out weird. For instance, even with traditional mode enabled, "SELECT 1 / 0;" still returns NULL, 'cause apparently the ERROR_FOR_DIVISION_BY_ZERO option only errors out on INSERTs and UPDATEs; meanwhile, for SELECTs, a warning is silently produced.

I didn't know about that. That is not very well implemented.

quote:

Further to that, why do they handle division by zero but not the square root of negative numbers or any other situation where the result of an expression is mathematically undefined? This works fine:

code:
mysql> insert into testing values (sqrt(-1));
Query OK, 1 row affected (0.04 sec)
Even with traditional mode enabled and all that. I'd expect that INSERT to error out as well, there doesn't seem to be an equivalent for ERROR_FOR_DIVISION_BY_ZERO for such undefined operations. MySQL's stance seems to be "when something is wrong, NULL is the answer." NULL isn't supposed to be some catch-all hand waving solution that solves all of life's problems in database management, it's supposed to represent that there is an absence of a value. In situations like this, we don't have an absence of a value but rather we know that the result of the expression is undefined mathematically, which is different than being absent.

Yeah, I would agree that throwing an error would be appropriate here. Although as a mathematician I feel the need to be picky and say that the result isn't "undefined mathematically", it just isn't a value that MySQL is designed to be able to manipulate. But it is a definite value and NULL isn't appropriate.

quote:

Speaking of collation support, I find it bizarre that the default encoding and collation settings are latin1 and latin1_swedish_ci respectively. Collation is a bit harder to default, I guess, and I know MySQL AB is based in Sweden, but I would at least think that these days UTF-8 would be the more popular choice for the encoding.

Arguably, but you have to bear in mind that MySQL will reserve 3 bytes per character if you make a CHAR column UTF-8, so it is not without side-effects.

quote:

The swappable storage engines can be alluring, but in the end it seems to cause so many headaches that you start to wonder if it's worth it.

You could take either of two positions on the subject. On the one hand you could say that it's good to have swappable storage engines in principle, because it means that developers have the freedom to create engines optimised for all sorts of different tasks. This is largely a theoretical advantage, although you can see it to a certain extent in the existence of the ARCHIVE and MEMORY engines. On the other hand you could argue that it leads to huge duplication of effort and results in none of the engines being as polished as a single engine could be if it was focused on by the design team.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
So we have an automated process where students upload their C++ code and we use an Ant script (Ant for building C++, ugh, I know I know) to compile and run it. We use the cpptasks library for this.

The version of cpptasks we're using on our server is slightly outdated, so this bug may be fixed now, but it's one of the most idiotic things I've ever seen. When you want to link to libraries in the build, you do something like this:

code:
<libset libs="bfd,iberty,intl"/>
Simple enough, right? Well I wanted to add libz.a to the build so I changed it to this:

code:
<libset libs="bfd,iberty,intl,z"/>
I started getting StringIndexOutOfBoundsExceptions from the build process. Why? Because the author did the most moronic way of checking to see if the library's name started with "lib". Instead of doing the obvious thing -- libnames[i].startsWith("lib") -- they do this instead:

code:
if (libnames[i].substring(0,3).equalsIgnoreCase("lib")) {
So of course it won't work for lib names shorter than 3 characters :psyduck: Even worse, if I try to put "lib" on the front thinking it will just strip it off, nope! It spits out an error saying "Don't prefix your libraries with 'lib'." Literally the only option (until I upgrade cpptasks if it's fixed) was to create a copy of the library with a longer name and use that instead :psypop:

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Flobbster posted:

if I try to put "lib" on the front thinking it will just strip it off, nope! It spits out an error saying "Don't prefix your libraries with 'lib'."
Ah, the classic "I know what you did and could easily work around it but don't want to" design pattern.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Mustach posted:

Ah, the classic "I know what you did and could easily work around it but don't want to" design pattern.

This is my favorite design pattern when dealing with websites. It takes less text to write "16 characters, no dashes or spaces" than to just do "input =~ s/[\w\-]//g".

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.

Hammerite posted:

On the one hand you could say that it's good to have swappable storage engines in principle, because it means that developers have the freedom to create engines optimised for all sorts of different tasks. This is largely a theoretical advantage,
I think it comes from the Linux perspective of saying "we want to have all possible options and all have possible extension points available". Less choice is not just "less choice", it's typically also "more focus", which is what a lot of these projects are lacking.

shrughes
Oct 11, 2008

(call/cc call/cc)
:psyduck: :psyduck: :psyduck:

Safe Memory Usage in C#

:drugnerd: Usually, the C# garbage collector does a pretty good job. The problem is, however, that you constantly run the risk of running out of memory in the middle of a program.

Part 1: http://cspangled.blogspot.com/2010/04/safe-memory-usage-in-c-part-12.html

:drugnerd: Keeping track of which memory is allocated is done via the LinearMemory.bounds member, which is a boolean array of the same length as the LinearMemory.mem byte array. When reserving a chunk of memory from 40 to 49, we simply set up "fenceposts" by setting bounds[40] and bounds[49] to true to mark the area as reserved. This way the malloc() function can just scan for the first big enough chunk of memory that is outside two "fenceposts", and the free() function can just scan along the memory from the given pointer to the next "fencepost" to know exactly which memory chunk to free. Since the bounds array takes up only 1/8 (remember, a boolean need only 1 bit!) of the mem array, it's not much overhead. If we say that the mem array is of size O(n), then the bounds array is of size O(n/8)=O(n).

This gives us a total of O(2n), which is linear. Since you can't go better than linear when dealing with memory, this model is pretty tight.

Part 1: Followup: http://cspangled.blogspot.com/2010/04/safe-memory-usage-in-c-part-12-followup.html

You'll hit OOM when you deserialize them, and much sooner.

:drugnerd: My very simplified Hello World introductory example is probably to blame for this one. The objects should not be "serialized" and "deserialized", they should be created, manipulated, and used entirely within the LinearMemory. You will be happy to know that the more advanced examples I have lined up for part two does exactly that!

As soon as he implied that leaving a server running would cause out of memory errors in a completely different process, he demonstrated that he really doesn't understand virtual memory at all.

:drugnerd: I always feel ill at ease responding to people who comment with the "smackdown" approach. Not because the comment itself hurts my feelings or some such, but because if I point out errors in their post I make them look rather stupid in front of everyone. That would make me feel bad, so that's why I politely decide to reply here instead of directly in the Reddit comments: You forget that virtual memory is still finite. That means one process can still use too much of available (virtual and physical) memory, leaving not enough for your process.

Part 2: http://cspangled.blogspot.com/2010/04/safe-memory-usage-in-c-part-22.html

:drugnerd: Serialization is a no-go; we need to write functions to read and manipulate live data inside the LinearMemory. For the new structures I intend to introduce, we only need to extend the LinearMemoryTools a little so it can interpret integers in addition to strings. Each number is simply encoded in 5 big-endian bytes


:psyduck: :psyduck: :psyduck:
:psyduck: :psyduck: :psyduck:
:psyduck: :psyduck: :psyduck:

code:
// LinearMemory.cs
namespace LinearMemoryEntry {
    using System.Linq;

    static class LinearMemory {
        public static byte[] mem;
        private static bool[] bounds;

        static LinearMemory() {
            // Allocate 10 megabytes initially.
            mem = new byte[1024 * 1024 * 10];
            bounds = new bool[mem.Count()];
            for (int i = 0; i < mem.Count(); bounds[i++] = false) ;
        }

        /// <summary>
        /// Allocate memory.
        /// </summary>
        /// <param name="size">Size of memory to allocate.</param>
        /// <returns>Ptr to newly allocated memory</returns>
        public static int malloc(int size) {
            int ptr = FindArea(0, size);
            bounds[ptr] = true;
            bounds[ptr + size - 1] = true;
            return ptr;
        }

        /// <summary>
        /// Free allocated memory.
        /// </summary>
        /// <param name="ptr">Ptr to allocated memory.</param>
        public static void free(int ptr) {
            bounds[ptr] = false;
            int i = ptr;
            while (!bounds[++i]);
            bounds[i] = false;
        }

        /// <summary>
        /// Copy a chunk of memory.
        /// </summary>
        /// <param name="srcPtr">Memory to copy from.</param>
        /// <param name="tgtPtr">Memory to copy to.</param>
        /// <param name="len">Length of memory chunk.</param>
        public static void memcpy(int srcPtr, int tgtPtr, int len) {
            for (int i = 0; i < len; i++)
                mem[tgtPtr + i] = mem[srcPtr + i];
        }

        private static int FindArea(int from, int size) {
            tryAgain:
            int foundSize = 0;
            int at = from;
            while (foundSize < size) {
                if (at >= mem.Count())
                    throw new OutOfMemoryException();
                if (bounds[at]) {
                    while (!bounds[++at]) ;
                    from = at + 1;
                    goto tryAgain;
                }
                foundSize++;
                at++;
            }
            return from;
        }
    }
}
:psyboom:

HFX
Nov 29, 2004

shrughes posted:

:psyduck: :psyduck: :psyduck:

Safe Memory Usage in C#

:drugnerd: Usually, the C# garbage collector does a pretty good job. The problem is, however, that you constantly run the risk of running out of memory in the middle of a program.

Part 1: http://cspangled.blogspot.com/2010/04/safe-memory-usage-in-c-part-12.html

:drugnerd: Keeping track of which memory is allocated is done via the LinearMemory.bounds member, which is a boolean array of the same length as the LinearMemory.mem byte array. When reserving a chunk of memory from 40 to 49, we simply set up "fenceposts" by setting bounds[40] and bounds[49] to true to mark the area as reserved. This way the malloc() function can just scan for the first big enough chunk of memory that is outside two "fenceposts", and the free() function can just scan along the memory from the given pointer to the next "fencepost" to know exactly which memory chunk to free. Since the bounds array takes up only 1/8 (remember, a boolean need only 1 bit!) of the mem array, it's not much overhead. If we say that the mem array is of size O(n), then the bounds array is of size O(n/8)=O(n).

This gives us a total of O(2n), which is linear. Since you can't go better than linear when dealing with memory, this model is pretty tight.

Part 1: Followup: http://cspangled.blogspot.com/2010/04/safe-memory-usage-in-c-part-12-followup.html

You'll hit OOM when you deserialize them, and much sooner.

:drugnerd: My very simplified Hello World introductory example is probably to blame for this one. The objects should not be "serialized" and "deserialized", they should be created, manipulated, and used entirely within the LinearMemory. You will be happy to know that the more advanced examples I have lined up for part two does exactly that!

As soon as he implied that leaving a server running would cause out of memory errors in a completely different process, he demonstrated that he really doesn't understand virtual memory at all.

:drugnerd: I always feel ill at ease responding to people who comment with the "smackdown" approach. Not because the comment itself hurts my feelings or some such, but because if I point out errors in their post I make them look rather stupid in front of everyone. That would make me feel bad, so that's why I politely decide to reply here instead of directly in the Reddit comments: You forget that virtual memory is still finite. That means one process can still use too much of available (virtual and physical) memory, leaving not enough for your process.

Part 2: http://cspangled.blogspot.com/2010/04/safe-memory-usage-in-c-part-22.html

:drugnerd: Serialization is a no-go; we need to write functions to read and manipulate live data inside the LinearMemory. For the new structures I intend to introduce, we only need to extend the LinearMemoryTools a little so it can interpret integers in addition to strings. Each number is simply encoded in 5 big-endian bytes


:psyduck: :psyduck: :psyduck:
:psyduck: :psyduck: :psyduck:
:psyduck: :psyduck: :psyduck:

code:
// LinearMemory.cs
namespace LinearMemoryEntry {
    using System.Linq;

    static class LinearMemory {
        public static byte[] mem;
        private static bool[] bounds;

        static LinearMemory() {
            // Allocate 10 megabytes initially.
            mem = new byte[1024 * 1024 * 10];
            bounds = new bool[mem.Count()];
            for (int i = 0; i < mem.Count(); bounds[i++] = false) ;
        }

        /// <summary>
        /// Allocate memory.
        /// </summary>
        /// <param name="size">Size of memory to allocate.</param>
        /// <returns>Ptr to newly allocated memory</returns>
        public static int malloc(int size) {
            int ptr = FindArea(0, size);
            bounds[ptr] = true;
            bounds[ptr + size - 1] = true;
            return ptr;
        }

        /// <summary>
        /// Free allocated memory.
        /// </summary>
        /// <param name="ptr">Ptr to allocated memory.</param>
        public static void free(int ptr) {
            bounds[ptr] = false;
            int i = ptr;
            while (!bounds[++i]);
            bounds[i] = false;
        }

        /// <summary>
        /// Copy a chunk of memory.
        /// </summary>
        /// <param name="srcPtr">Memory to copy from.</param>
        /// <param name="tgtPtr">Memory to copy to.</param>
        /// <param name="len">Length of memory chunk.</param>
        public static void memcpy(int srcPtr, int tgtPtr, int len) {
            for (int i = 0; i < len; i++)
                mem[tgtPtr + i] = mem[srcPtr + i];
        }

        private static int FindArea(int from, int size) {
            tryAgain:
            int foundSize = 0;
            int at = from;
            while (foundSize < size) {
                if (at >= mem.Count())
                    throw new OutOfMemoryException();
                if (bounds[at]) {
                    while (!bounds[++at]) ;
                    from = at + 1;
                    goto tryAgain;
                }
                foundSize++;
                at++;
            }
            return from;
        }
    }
}
:psyboom:

:psyboom: What the hell? I read a little bit in and reached the statement about it being a well known problem in the game industry and you allocate up front and manually manage it all. It isn't about running out of memory all the sudden. Did he even read the article he linked? :psyboom: Wait, does he know how a garbage collector works? This is C# which I can't imagine doing anything different from the other garbage collectors. :psyboom:

I do manual memory management on one platform not because I have to but because the memory management system regularly screws up with deletes. This leads to a host problems such as running out of memory, or overwriting other values. Good luck getting anyone from that company to fix it though.

HFX fucked around with this message at 22:36 on Jul 6, 2010

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
code:
31              /// <summary>
32	        /// Retrieve a string from memory.
33	        /// </summary>
34	        /// <param name="ptr">Ptr to string.</param>
35	        /// <param name="len">Len of string.</param>
36	        /// <returns></returns>
37	        public static string BytesString(int ptr, int len) {
38	            return enc.GetString(LinearMemory.mem, ptr, len);
39	        }
:lol::lol:
code:
01	//PARTIAL LinearMemoryTools.cs
02	/// <summary>
03	/// Access the bytes of a int.
04	/// </summary>
05	/// <param name="i">The int.</param>
06	/// <returns>The bytes.</returns>
07	public static byte[] IntBytes(int i) {
08	    if (i > int.MaxValue) throw new OverflowException("int too big!");
09	    bool positive = false;
10	    if (i > 0) positive = true;
11	    i = Math.Abs(i);
12	    byte[] bytes = new byte[5];
13	    bytes[0] = (byte)(i / 16777216);
14	    i = i % 16777216;
15	    bytes[1] = (byte)(i / 65536);
16	    i = i % 65536;
17	    bytes[2] = (byte)(i / 256);
18	    i = i % 256;
19	    bytes[3] = (byte)(i);
20	    bytes[4] = positive ? (byte)'P' : (byte)'N';
21	    return bytes;
22	}
23	 
24	/// <summary>
25	/// Retrieve a int from memory.
26	/// </summary>
27	/// <param name="ptr">Ptr to int.</param>
28	/// <param name="len">Must be 5.</param>
29	/// <returns>The int.</returns>
30	public static int BytesInt(int ptr, int len) {
31	    int i = 0;
32	    i += 16777216 * LinearMemory.mem[ptr + 0];
33	    i += 65536 * LinearMemory.mem[ptr + 1];
34	    i += 256 * LinearMemory.mem[ptr + 2];
35	    i += LinearMemory.mem[ptr + 3];
36	    if (LinearMemory.mem[ptr + 4] == (byte)'N')
37	        i = -i;
38	    return i;
39	}
:lol::lol::lol:

quote:

As programming guru Joel says, real programmers need to understand pointers.
This has got to be a parody of something.

Nippashish
Nov 2, 2005

Let me see you dance!
code:
//Employee.cs
public static class Employee {
    private const int OFF_NAME____ =  0;
    private const int OFF_NAME_LEN = OFF_NAME____ + 20;
    private const int OFF_SALARY__ = OFF_NAME_LEN + 5;
    private const int OFF_PHONE___ = OFF_SALARY__ + 5;

    public static int Size = OFF_PHONE___ + 5;
    
    public static int Create(string name, int salary, int phone) {
        if (name.Length > 20)
            throw new OverflowException("name too long! max 20 chars");
        int p = LinearMemory.malloc(Size);
        LinearMemoryTools.Insert(p + OFF_NAME____,
                                 LinearMemoryTools.StringBytes(name));
        LinearMemoryTools.Insert(p + OFF_NAME_LEN,
                                 LinearMemoryTools.IntBytes(name.Length));
        LinearMemoryTools.Insert(p + OFF_SALARY__,
                                 LinearMemoryTools.IntBytes(salary));
        LinearMemoryTools.Insert(p + OFF_PHONE___,
                                 LinearMemoryTools.IntBytes(phone));
        return p;
    }
}
Why yes, I do want to manually specify the offset of each of my data members. It's okay though, since the members are private. Once we add getters and setters it will be fully object oriented.

quote:

While I don't know exactly the algorithm for Turing's machine, I think the LinearMemory is well suited to encryption in general, sice you have free access directly to the bytes. You could even encrypt and decrypt an object in-place!

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
Did he really align his equals signs by putting underscores after the variable names? :smithicide:

Adbot
ADBOT LOVES YOU

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

Janin posted:

Did he really align his equals signs by putting underscores after the variable names? :smithicide:

He didn't want to take sides in the spaces vs. tabs debate.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply