Live data from Hacker News

ProjectPSX – A C# coded emulator of the original Playstation

github.com

21–30 of 62 posts

Re: ProjectPSX – A C# coded emulator of the original Playstation

#21
post #13

Earlier quoted context omitted.

In fact, the techniques for C# here would be pretty much the same as for C++ or C: Don't do dynamic allocation in the hot path. And if you must, keep the lifetime short so it gets cleaned up predictably (usually in gen0). However, for an ancient platform on modern hardware I guess the per-frame budget is plentiful even for an emulator.

Yeah, which is the problem with GC'd languages because it isn't always obvious where allocation will occur.

In what concerns .NET there are Visual Studio plugins that mark exactly that.

D also has something similar as compiler switch.

Re: ProjectPSX – A C# coded emulator of the original Playstation

#22
post #20

Earlier quoted context omitted.

Yeah, which is the problem with GC'd languages because it isn't always obvious where allocation will occur.

In what case isn't it obvious? C# makes it quite clear, you allocate to memory on the heap whenever you see the "new" keyword or whenever you see a new closure (because closures are of course just a poor man's objects).

Not necessarily just those things. A foreach loop might have a heap allocation, async/await almost certainly, calling a method with a params[] parameter as well. Everything you call from the BCL might allocate, too and it's not always visible or obvious.

That being said, it is still doable to avoid allocations and the standard library has become much better with not allocating unless really necessary. A lot of the newer things with Span enable zero-allocation usage of certain APIs that before would have allocated.

Re: ProjectPSX – A C# coded emulator of the original Playstation

#23

Earlier quoted context omitted.

A platform independent desktop UI framework really is the biggest gap in the .NET platform right now, and I think Microsoft knows it. We'll probably see something new on that front soon, I'd wager.

> We'll probably see something new on that front soon MS has no interest in this space [0]. Your best bet at this moment is Electron or other open source alternates like eto forms. [0] - Scott hunter's .net rocks podcast. The related commentary is past 30 mins from beginning of the show - https://www.dotnetrocks.com/?show=1634

That is outdated.

They were running a developer survey about that

I bet our outcries are getting too loud in Redmond. Similar to those of us not bothering with Core until key frameworks got ported.

https://devblogs.microsoft.com/dotnet/calling-all-net-deskto...

Re: ProjectPSX – A C# coded emulator of the original Playstation

#24
post #7

As a day-to-day C# developer, I'm curious about a few things: - Do you ever find that the Garbage Collector causes noticeable pausing in the emulator? - Did you do this with 100% managed memory, or do you need to use unsafe code / real pointers? (Apologies that I didn't read the source code.)

Search the repo for "new" and you'll see that everything is allocated at construction time. Everything hangs off the window class so essentially all memory is allocated as the project starts up. You'd probably want to pre-allocate in any language because but this also relieves GC pressure.

Another thing you can do in C# is leverage stack allocation using structs.

Re: ProjectPSX – A C# coded emulator of the original Playstation

#25
post #16

Earlier quoted context omitted.

A platform independent desktop UI framework really is the biggest gap in the .NET platform right now, and I think Microsoft knows it. We'll probably see something new on that front soon, I'd wager.

I hope. But I don't hold my breath before .NET 5. 3.0 is all about getting Windows Desktop scenarios to .NET Core. Not many of the people who require those would benefit from a cross-platform framework, as neither Windows Forms nor WPF would be portable. Avalonia might have the chance of becoming a decent option, but even working for an employer that provides GUI controls for various platforms it's too early to decid…

Except 2-1 laptops are also desktops, which many seem to keep forgetting.

Re: ProjectPSX – A C# coded emulator of the original Playstation

#26
post #22
post #20

Earlier quoted context omitted.

In what case isn't it obvious? C# makes it quite clear, you allocate to memory on the heap whenever you see the "new" keyword or whenever you see a new closure (because closures are of course just a poor man's objects).

Not necessarily just those things. A foreach loop might have a heap allocation, async/await almost certainly, calling a method with a params[] parameter as well. Everything you call from the BCL might allocate, too and it's not always visible or obvious. That being said, it is still doable to avoid allocations and the standard library has become much better with not allocating unless really necessary. A lot of the ne…

And even if you use structs with the goal of avoiding allocations, the language doesn't prevent you from accidentally writing code that upcasts them to `object` (eg by calling anything that the struct inherits from `object` and isn't overridden by the struct itself.) This transparently copies the struct to a heap allocation and negates your intent.

Re: ProjectPSX – A C# coded emulator of the original Playstation

#27

Earlier quoted context omitted.

A platform independent desktop UI framework really is the biggest gap in the .NET platform right now, and I think Microsoft knows it. We'll probably see something new on that front soon, I'd wager.

> We'll probably see something new on that front soon MS has no interest in this space [0]. Your best bet at this moment is Electron or other open source alternates like eto forms. [0] - Scott hunter's .net rocks podcast. The related commentary is past 30 mins from beginning of the show - https://www.dotnetrocks.com/?show=1634

I wouldn't be surprised, now that Microsoft owns Electron, if the new UI framework took a form similar to Electron, but I am sure Microsoft will need to have something with close integration for C#/VB development.

Re: ProjectPSX – A C# coded emulator of the original Playstation

#28
post #22

Earlier quoted context omitted.

Not necessarily just those things. A foreach loop might have a heap allocation, async/await almost certainly, calling a method with a params[] parameter as well. Everything you call from the BCL might allocate, too and it's not always visible or obvious. That being said, it is still doable to avoid allocations and the standard library has become much better with not allocating unless really necessary. A lot of the ne…

And even if you use structs with the goal of avoiding allocations, the language doesn't prevent you from accidentally writing code that upcasts them to `object` (eg by calling anything that the struct inherits from `object` and isn't overridden by the struct itself.) This transparently copies the struct to a heap allocation and negates your intent.

This is not entirely true as of C# 7.2. That version of the language adds "ref structs" - which can only be allocated on the stack and cannot be boxed [1].

This requires some care though, as the struct may still be copied needlessly if it is not also marked as `readonly` [2].

[1] - https://blogs.msdn.microsoft.com/mazhou/2018/03/02/c-7-serie... [2] - https://docs.microsoft.com/en-us/dotnet/csharp/write-safe-ef...

Re: ProjectPSX – A C# coded emulator of the original Playstation

#29
post #7

As a day-to-day C# developer, I'm curious about a few things: - Do you ever find that the Garbage Collector causes noticeable pausing in the emulator? - Did you do this with 100% managed memory, or do you need to use unsafe code / real pointers? (Apologies that I didn't read the source code.)

Hello There, I'm the owner of this repo. So nice that has ended here somehow. Gonna answer the upper quests...

- Do you ever find that the Garbage Collector causes noticeable pausing in the emulator?

The GC dosn't cause noticeable pausing on my setup. Even tho it could allocate less.

- Did you do this with 100% managed memory, or do you need to use unsafe code / real pointers?

In fact it was done without unsafe code or pointers till some of the latest commits. Where i switched to unsafe because performance reasons. On my setup that was arround 10 fps more.

Re: ProjectPSX – A C# coded emulator of the original Playstation

#30
post #22

Earlier quoted context omitted.

Not necessarily just those things. A foreach loop might have a heap allocation, async/await almost certainly, calling a method with a params[] parameter as well. Everything you call from the BCL might allocate, too and it's not always visible or obvious. That being said, it is still doable to avoid allocations and the standard library has become much better with not allocating unless really necessary. A lot of the ne…

And even if you use structs with the goal of avoiding allocations, the language doesn't prevent you from accidentally writing code that upcasts them to `object` (eg by calling anything that the struct inherits from `object` and isn't overridden by the struct itself.) This transparently copies the struct to a heap allocation and negates your intent.

[deleted]
Post reply on HN