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.
 
  • Locked thread
Luigi Thirty
Apr 30, 2006

Emergency confection port.

The 1541 was a full 6502-based computer running its own DOS. It communicated over a (slow af) serial link with the computer. You told the drive to read a file and it did so. It was only capable of using the Commodore GCR format. It cost $400 on release in 1982.

The Disk II was a Woz controller board and a Shugart disk mechanism in a metal box. It’s dumb as hell and almost entirely software controlled.

The read/write head and motor are manually controlled by hitting memory-mapped IO registers. DOS is present on floppies. Depending on the DOS and revision of the disk hardware, the disk format could be inefficient 4-and-4 GCR, slightly more efficient 5-and-3 GCR, or efficient 6-and-2 GCR. The difference between them being how many data bits you can fit into a byte on disk and reliably read it. 6-and-2 means there are 6 data bits per byte.

The trademark grinding you hear when you turn on an Apple II is the controller card seeking track 0. To save money, there’s no track 0 sensor in the disk mechanism. The controller just cycles the stepper motor in the drive to move the head toward the outside of the drive over and over. The noise is the head hitting a stopper that physically blocks it from going any further.

To find a specific sector, DOS tells the drive to go to the track it’s on, then spins the motor until the sector is under the read head. Each sector starts with some metadata that tells the software the current track and sector number. When the software detects the right sector, it’s read in and converted to 8-bit words using a lookup table.

An advantage of this is that it’s flexible: Apple drives could read and write any format as long as the head could physically do it. The Microsoft CP/M card included a controller that let the drive read MFM-formatted disks. This also let people come up with weird encoding schemes for copy protection, since you could override DOS’ built-in read/write routines with custom ones.

Now if I could just get my emulator booting a dang DOS 3.3 Master Disk

Adbot
ADBOT LOVES YOU

MrMoo
Sep 14, 2000

something different on sorting,

https://www.youtube.com/watch?v=sYd_-pAfbBw&t=179s

Lutha Mahtin
Oct 10, 2010

Your brokebrain sin is absolved...go and shitpost no more!

CPColin posted:

I have discovered a truly marvelous solution to CSS, which this margin-right is too narrow to contain.

:prepop:

CPColin
Sep 9, 2003

Big ol' smile.

HoboMan posted:

also re logging: lol, what framework?
each time we log something it takes about 200ms. compared to other bottlenecks it's not that bad, but it seemed like an excessive amount of overhead

At my last job, we couldn't figure out why our web servers tended to time out right after logging an error. It turned out that somebody, long ago, had made the Java code run a process that added the error message to the system log. When you tell Java to run a process on certain operating systems, the JVM does a fork() call. When the server had been running for a while, that fork caused a long pause as the 8GB of process memory was dealt with. The load balancer, at the time, killed servers that didn't respond immediately to the heartbeat check.

This hadn't previously been noticed because the code logged errors often enough that the first error tended to happen while the memory footprint was still small. Once we actually put some effort into cleaning up the constant nagging, servers started to have a chance of running for hours before logging their first error.

The solution was to fork the process while the server was starting up, so the memory footprint was still small and the load balancer's restart logic wasn't enabled yet. Eventually, somebody thankfully got rid of that code. When I left, there still wasn't a logging framework in place.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I thought "psh, I’ve already seen all the cool sorting visualizations"

I was wrong

MononcQc
May 29, 2007

I've just recently found out about code using ligatures to do fancy operator representation without requiring unicode in code and I'm loving that poo poo

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

this is white hot

i yelled holy poo poo when it did in place radix sort

DONT THREAD ON ME fucked around with this message at 02:22 on Aug 5, 2017

VikingofRock
Aug 24, 2008





this is extremely my jam

pram
Jun 10, 2001

soothes the tism

Foo Diddley
Oct 29, 2011

cat

usually i just lurk but i have to say that this owns

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Luigi Thirty posted:

This also let people come up with weird encoding schemes for copy protection, since you could override DOS’ built-in read/write routines with custom ones.

one cool thing about all that copy protection built around having its own RWTS (read/write track/sector) is that it winds up easy to replace, once cracked, with code that’ll work under a real OS, on a hard disk, etc.

redleader
Aug 18, 2005

Engage according to operational parameters

ho hum, yet another sorting visualizaHOLY poo poo

gonadic io
Feb 16, 2011

>>=

MononcQc posted:

I've just recently found out about code using ligatures to do fancy operator representation without requiring unicode in code and I'm loving that poo poo

it's extremely good yeah. i have it in my terminal and all my editors

VikingofRock
Aug 24, 2008




Foo Diddley posted:

usually i just lurk but

:justpost:

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

MononcQc posted:

I've just recently found out about code using ligatures to do fancy operator representation without requiring unicode in code and I'm loving that poo poo

i actually had to stop using fira code because of ligatures. there was no way to turn them off in Eclipse and my brains just too used to parsing != as is in java. sad cuz i lived fira code in my mumps editor.

tef
May 30, 2004

-> some l-system crap ->

Radix LSD :2bong:

to people who haven't clicked, this also visualizes the relative displacement of elements sort separately from it's value/position in list

JewKiller 3000
Nov 28, 2006

by Lowtax
the only reason to ever have a null is if you need to initialize a variable without actually providing a value. you don't need to do this, even if you think you do, but you know, arrays and poo poo. still not necessary, but you're a micro-optimizing rear end in a top hat, aren't you? fine, have your null and eat it too

option types (as one of the most basic uses of algebraic datatypes) were introduced to general purpose programming languages in the nineteen-loving-seventies. there is no loving excuse for a null pointer exception ever

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

JewKiller 3000 posted:

the only reason to ever have a null is if you need to initialize a variable without actually providing a value. you don't need to do this, even if you think you do, but you know, arrays and poo poo. still not necessary, but you're a micro-optimizing rear end in a top hat, aren't you? fine, have your null and eat it too

option types (as one of the most basic uses of algebraic datatypes) were introduced to general purpose programming languages in the nineteen-loving-seventies. there is no loving excuse for a null pointer exception ever

what if i want to crash immediately on a null without having to explicitly null check everywhere?

Soricidus
Oct 21, 2010
freedom-hating statist shill
nullability inference in ides is extremely good and cool if you're using a language with endemic nulls

if you write a java and you return null from a method without annotating it as @Nullable then you are a terrible person and I hope you choke on a null

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Soricidus posted:

if you write a java and you return null from a method without annotating it as @Nullable then you are a terrible person and I hope you choke on a null

yeah, but which @Nullabe?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

cis autodrag posted:

what if i want to crash immediately on a null without having to explicitly null check everywhere?

practically every option type implementation has a "get if exists, crash otherwise" if that's what you really really want to do

Soricidus
Oct 21, 2010
freedom-hating statist shill

Wheany posted:

yeah, but which @Nullabe?

I don't think it matters does it? pretty sure ides recognise all the common ones now

Notorious b.s.d.
Jan 25, 2003

by Reene

CPColin posted:

At my last job, we couldn't figure out why our web servers tended to time out right after logging an error. It turned out that somebody, long ago, had made the Java code run a process that added the error message to the system log. When you tell Java to run a process on certain operating systems, the JVM does a fork() call. When the server had been running for a while, that fork caused a long pause as the 8GB of process memory was dealt with. The load balancer, at the time, killed servers that didn't respond immediately to the heartbeat check.

This hadn't previously been noticed because the code logged errors often enough that the first error tended to happen while the memory footprint was still small. Once we actually put some effort into cleaning up the constant nagging, servers started to have a chance of running for hours before logging their first error.

The solution was to fork the process while the server was starting up, so the memory footprint was still small and the load balancer's restart logic wasn't enabled yet. Eventually, somebody thankfully got rid of that code. When I left, there still wasn't a logging framework in place.

fork is copy-on-write, so normally, forking an 8gb process is nbd and everything is fine

but, java's garbage collector, being a generational gc, is gonna write a shitload of memory any time it promotes things between generations.

so you fork, everything is fine for 100ms, and then it all goes to hell copying pages the moment the gc runs

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Notorious b.s.d. posted:

fork is copy-on-write, so normally, forking an 8gb process is nbd and everything is fine

even with copy-on-write, even with vfork(), there's still a lot of overhead to forking a process when you're just going to throw away almost all its context

that's why posix_spawn() exists, as flawed as it is (and boy is it flawed: you need to use nonportable extensions to choose which file descriptors to preserve/close, the per-thread working directory is used to set the working directory for the new process, etc.)

using posix_spawn() vs fork() can make a significant difference in performance when you have a heavyweight process that needs to start tons of processes that inherit almost nothing (such as an IDE starting compilers)

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I'm lost are you guys saying that forking any process will copy the originals memory? so an 8GB JVM gets copied each time you fork?

suffix
Jul 27, 2013

Wheeee!

Soricidus posted:

ask me about trying to convince a co-worker that it is a bad idea for your code to check whether it is about to return an empty collection, and deliberately return null instead

Java code:
public Collection<Bar> foosIntoBars(Collection<Foo> foos) {
    if (NullUtil.isEmptyOrNull(foos)) {
        return null;
    }
   ...
}

static public void main(String[] argv) {
    ...
    Collection<Bar> bars = NullUtil.emptyListIfNull(foosIntoBars(foos)));
   ...
}

CPColin
Sep 9, 2003

Big ol' smile.

Janitor Prime posted:

I'm lost are you guys saying that forking any process will copy the originals memory? so an 8GB JVM gets copied each time you fork?

Forking shouldn't copy anything right away, but if the JVM does a garbage collection right after the fork happens, a bunch of pages will be copied-on-write and the system will bog down. I think this was on FreeBSD at the time and that OS had some weird interaction with the JVM that was making things worse.

qhat
Jul 6, 2015


i've solved lots of dumb java bugs just by changing functions that return null and getting them to return some kind of empty structure that you'd expect. throwing works too. never return null, there's no reason to ever do it.

akadajet
Sep 14, 2003

Foo Diddley posted:

usually i just lurk

you must post

Luigi Thirty
Apr 30, 2006

Emergency confection port.

I have no ram and I must fork

feedmegin
Jul 30, 2008

eschaton posted:

even with copy-on-write, even with vfork(), there's still a lot of overhead to forking a process when you're just going to throw away almost all its context

that's why posix_spawn() exists, as flawed as it is (and boy is it flawed: you need to use nonportable extensions to choose which file descriptors to preserve/close, the per-thread working directory is used to set the working directory for the new process, etc.)

using posix_spawn() vs fork() can make a significant difference in performance when you have a heavyweight process that needs to start tons of processes that inherit almost nothing (such as an IDE starting compilers)

Isnt the Linux implementation of posix_spawn literally just a fork then an exec?

Also, fork () without subsequent exec and Posix multithreading (like in a modern JVM) Do Not Mix, for what it's worth, though I guess we aren't talking about that here.

feedmegin fucked around with this message at 23:30 on Aug 5, 2017

Soricidus
Oct 21, 2010
freedom-hating statist shill
java status: tried to run our javafx app in the latest java 9 preview, got an instant crash because apparently you now need to ask specially for certain parts of the standard library using magic command-line incantations, or the jvm will just pretend it can't find them even though they're right fuckign there. added a few magic incantations copied from snack overflow, got another instant crash because apparently they've moved some classes around too. gently caress it i'll just pray it's someone else's problem by the time customers are demanding we support java 9

oh well, it's not like violently breaking backwards compatibility has ever hurt uptake of a new version of a programming language!!!

mystes
May 31, 2006

Soricidus posted:

java status: tried to run our javafx app in the latest java 9 preview, got an instant crash because apparently you now need to ask specially for certain parts of the standard library using magic command-line incantations, or the jvm will just pretend it can't find them even though they're right fuckign there. added a few magic incantations copied from snack overflow, got another instant crash because apparently they've moved some classes around too. gently caress it i'll just pray it's someone else's problem by the time customers are demanding we support java 9

oh well, it's not like violently breaking backwards compatibility has ever hurt uptake of a new version of a programming language!!!
All that stuff didn't end up being opt in or something after the argument about Jigsaw or whatever it's called?

cool av
Mar 2, 2013

NihilCredo posted:

dude it's literally the first goooooooooooogle result for ".net file_append_data"



google is hard yo

but yes I looked back at my logging code and it's not p/invoke; I think all the win32-ish flags gave it that aura in my memory

Luigi Thirty
Apr 30, 2006

Emergency confection port.

holy poo poo i got my apple 2 emulator to boot a DOS 3.3 master disk i am a goddamn wizard



"i kinda feel like god" --cereal killer, the hackers movie

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

suffix posted:

Java code:
public Collection<Bar> foosIntoBars(Collection<Foo> foos) {
    if (NullUtil.isEmptyOrNull(foos)) {
        return null;
    }
   ...
}

static public void main(String[] argv) {
    ...
    Collection<Bar> bars = NullUtil.emptyListIfNull(foosIntoBars(foos)));
   ...
}

code:
public Collection<Bar> foosIntoBars(Collection<Foo> foos) {
    if (NullUtil.isEmptyOrNull(foos)) {
        return Collections.singletonList(null);
    }
    ...
}
:unsmigghh:

VikingofRock
Aug 24, 2008




So I have some C++ code that I'd like some feedback on, if someone has time to look at it. It's a class which handles concurrent memoization of the results of a function for various inputs, so that the function is only called once for each set of arguments. Here's what I've got:

C++ code:
#include <map>
#include <mutex>
#include <tuple>

template <typename Value, typename F, typename ...Args>
class memo {
private:
    F calculate_;
    std::map<std::tuple<Args...>, Value> results_;
    std::mutex results_mutex_;
    // ^ lock before accessing results_
    std::map<std::tuple<Args...>, std::once_flag> calculation_flags_;
    std::mutex calc_flags_mutex_;
    // ^ lock before accessing calculation_flags_
public:
    /* Construct a memo, which stores a function `calculate` which takes
     * arguments of types `Args...` and which returns an object of type `Value`.
     * This memo will then store the results of `calculate` for each set of
     * arguments passed to `get()`, so that `calculate` is only called once
     * for each set of arguments.
     */
    explicit memo(F calculate): calculate_(calculate) {}

    /* Get the result for the memoized function given the arguments `args`. The
     * memoized function is called exactly once. Multiple concurrent calls to
     * `get` are thread safe, with all calls hanging until the stored calculation
     */
    Value get(Args... args) {
        auto key = std::make_tuple(args...);
        {
            std::lock_guard<std::mutex> calc_flags_lock(calc_flags_mutex_);
            // Add a once flag for `args` if it doesn't already exist
            // Note: map.emplace() will not overwrite a duplicate key
            calculation_flags_.emplace(
                std::piecewise_construct,
                std::forward_as_tuple(key),
                std::forward_as_tuple()
                // ^ gotta jump through hoops to avoid copying a once_flag
            );
        }
        std::call_once(
            calculation_flags_.at(key),
            [this, &key, &args...] () {
                Value result = calculate_(args...);
                std::lock_guard<std::mutex> results_lock_(results_mutex_);
                results_.emplace(key, result);
            }
        );
        std::lock_guard<std::mutex> results_lock_(results_mutex_);
        return results_.at(key);
    }
};
I suspect this sort of thing has already been implemented somewhere, but it was still a valuable exercise even if I did reinvent the wheel. I'd be curious to get some feedback on it. One thing I thought about was not having the argument types be part of the memo template parameter list, but I think that's asking for trouble with functions with default arguments. Also I'm only like 30% certain I got the concurrency right because concurrency is hard.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Luigi Thirty posted:

holy poo poo i got my apple 2 emulator to boot a DOS 3.3 master disk i am a goddamn wizard



"i kinda feel like god" --cereal killer, the hackers movie

what did it take?

Soricidus
Oct 21, 2010
freedom-hating statist shill

mystes posted:

All that stuff didn't end up being opt in or something after the argument about Jigsaw or whatever it's called?

not all of it, no

so by default it will allow some reflective access of certain parts of the standard library now. that's all. and it dumps pages of warning messages to stderr telling users that the program is broken.

they have still pressed on with modularisation, and some modules are no longer available by default that used to be, so learn to love those command line flags!

and they have still (at least within javafx) happily made sweeping changes to things everyone was using even though they were technically private. some of these changes have been to make those things public -- but since this involved changing their names or packages, there is basically literally no way to have a non-trivial javafx program that runs on java 8 and java 9 without maintaining two versions of the code

Adbot
ADBOT LOVES YOU

Luigi Thirty
Apr 30, 2006

Emergency confection port.

eschaton posted:

what did it take?

the sector nibblizer math was screwed up and offset $100 and nothing else was being miscalculated, causing the read’s checksum to fail

I fixed that and now it boots DOS and runs programs from disk just fine

now i need to hook up writing out to the disk image instead of pretending all disks are write protected

  • Locked thread