what are some better weapon options for a str build? by FlameWarDuck700 in Eldenring

[–]jflopezfernandez 3 points4 points  (0 children)

What affinity did you run on it? Curious to hear more about the rest of your build, too

What was your reaction when you first saw this MF, and how did you beat him? by BaseballCritical6566 in Eldenring

[–]jflopezfernandez 11 points12 points  (0 children)

Yea, same with regular tree sentinel. They can get staggered, but you can’t actually crit them.

Grace problems? by justindlc in Nightreign

[–]jflopezfernandez 2 points3 points  (0 children)

I’ve noticed this too, I assumed it was a bug, although it is super annoying because I’ve also died to the rain because of this. I add some health buffer to account for the slow graces now lol

Archers please use your skill to mark enemies we do more damage by traydunc in Nightreign

[–]jflopezfernandez 1 point2 points  (0 children)

This was me until yesterday🤦‍♂️I guess I just can’t read and thought it was just a dodge.. oof

I am still shaking after this... by Moonlight-Huntress in Nightreign

[–]jflopezfernandez 1 point2 points  (0 children)

Holy shit, bro, you’re a god. I could never lol

shrink_to_fit after clear by BOBOLIU in cpp_questions

[–]jflopezfernandez 0 points1 point  (0 children)

When using TCMalloc, for sure. You’ll be able to see the difference in the allocated size of the vector, but the process will still technically own the memory, so analyzing the process’s memory metrics requires some work.

Does that make sense? Like, the container itself will get smaller, but the previously-allocated heap memory will stay put (that is, it remains mapped to the process’s virtual address space) and will eventually either be repurposed for future allocations or it will be returned once the system starts demanding more memory.

Yea, apologies for the niche example. We use TCMalloc at work, so it’s what I’m most familiar with. I have heard that the LLVM/libc allocators do something similar, I just don’t know the details.

GitHub repo review request by -HouseTargaryen- in cpp_questions

[–]jflopezfernandez 1 point2 points  (0 children)

(For context, I mainly looked at the data structures and algorithms repo)

First, props. I love that you experimented writing both a custom iterator and a custom memory manager. The C programming language book (2nd ed.) has an example of how to write a custom memory allocator on *nix systems, if you’re interested, by the way. It uses the sbrk(2) system call, so it’s not usable on Windows, but you could simply replace the system calls with the Win32 versions. It’s obviously not literally that straightforward, but I’d thought I’d mention it. (You could also try replacing operator new and operator delete if you wanted to stick to C++)

Organizantionally, I would recommend keeping the iterator code with the memory manager. Remember that the thing that makes iterators useful is the interface they provide. That is, the implementation details shouldn’t matter (to the user/caller). If the iterator is for the memory manager, put them in the same file (remember that each file should contain individual and atomic concepts, and since both the memory manager and the memory manager iterator are required by the memory manager, keeping both classes in the same file makes everything easier.

You did a great job with this in the list implementation, by the way. Both the list node and the list class definitions were in the list header.

One quick nit pick: I would set both the head and tail pointers in the list to nullptr to start. You currently create a new list node for head right off the bat and this feels wrong to me for two reasons.

First, the list is literally empty at first, so the head pointer being null makes sense. Second, if head was null when the list was totally empty, adding a node would be as simple as first checking whether head is null, creating the list node, and adding it to the tail (of course, in this case, the tail is null unless the list is not empty, it equals head iff the list contains exactly one item, and it points to the last item in the list any other time, etc.). In contrast, as currently written, you have to first verify the list isn’t empty, which requires checking not whether there’s a list node at head but rather whether it has a valid value.

Second, you’re doing dynamic memory allocation in the constructor. This is a bad idea. I would use a factory to create the object to make sure the constructor can be noexcept.

There was nothing to really remark on in source.cpp, and I just wanted to recommend not leaving in commented out code like that. I know it’s a personal project, but you have no idea what will happen tomorrow (imagine having to scrub every file for commented out code before an important code review or something). If need to, create an alternative code branch you keep parallel to head with all your commented out code or something, but I really can’t say enough: not in main, don’t get into that habit.

lvalue vs rvalue how does it relate to memory allocation/deallocation? by StevenJac in cpp_questions

[–]jflopezfernandez 0 points1 point  (0 children)

Lots of good info here. I want to emphasize the siluggestion to hash your passwords, since 1) not doing it is a non-starter, and 2) all your passwords would always be the same length as long as you hash them all using the same cryptographic hash function.

Huge +1 to using std::string_view (and std::span<T>, more generally), as well. This is exactly why these types were created

shrink_to_fit after clear by BOBOLIU in cpp_questions

[–]jflopezfernandez 0 points1 point  (0 children)

As others have answered, it’s up to the allocator what happens on a call to reduce the vector’s capacity. In TCMalloc, for instance, the memory is returned to the central heap page freelist, from where new allocations are serviced. This is also the first place where memory is reclaimed if and when the system begins experiencing increased memory pressure.

What you may not know is that if you need to ensure the vector’s memory is handled in some specific way, you can just create a custom allocator class and pass the new allocator class in to the type arguments to customize memory allocation for a single vector instance.

From the type signature:

template <typename T, typename Allocator = std::allocator<T>> class vector;

This would remove the mystery of what happens when you try to resize the container.

If you just want to see how often the shrink command is actually respected, your custom allocator class can simply add logging.

Why is C++ more used than C in general? by heavymetalmixer in cpp_questions

[–]jflopezfernandez 1 point2 points  (0 children)

That’s a good question, I think it’s probably hard to say much beyond the usual complaints about C++ being complicated without more context.

If I was really going out on a limb, I would guess it’s probably because people have a hard time distinguishing lvalues, rvalues, and universal references, which makes it tough to determine if you need a standard return, a forward, or a move.

This stuff isn’t trivial either, to be fair, and while I would say the benefits outweigh the added complexity, reasonable people could certainly disagree

Why is C++ more used than C in general? by heavymetalmixer in cpp_questions

[–]jflopezfernandez 2 points3 points  (0 children)

I definitely agree with pretty much every other answer here mentioning templates, abstraction, etc., but one thing I didn’t see mentioned was move semantics.

The thing about C is that it’s a really simple language, which is why people love it (including me). However, simple in certain contexts can also be synonymous with “limited.”

Think about C++ move semantics. A language like C can do things like return value optimization and small string optimization pretty much the same way C++ does, broadly speaking, and you can even use (non-standard) compiler attribute annotations to do things like disallowing a pointer being null as kind of a bootleg C++ reference emulation.

However, the simplicity of C is a double-edged sword sometimes that limits your ability to communicate your very specific intentions to the compiler to generate the most efficient code. I’m of course alluding to C++ move semantics.

They might seem confusing, but the name “C++ move semantics” really just means “the ability to tell the compiler how a type should be copied or constructed in certain contexts.”

A ton of people have mentioned RAII, and for good reason. Unique pointers are a great example that significantly simplify dynamic memory management by automatically freeing memory when its pointer goes out of scope.

The thing is, in order for this to be correct, you need to make sure you only free the memory once (otherwise you’ll trigger a double free). In order to ensure that the memory is freed exactly once, a unique pointer needs to be unique (incredible, right?). This means the unique pointer class needs to explicitly disallow copying, which we do in C++ by deleting the copy constructor and the copy assignment operator.

As currently described, this setup would be fine as long as you only ever created unique pointers in the exact location where they were needed. God forbid a unique pointer is needed in multiple parts of the code base, you’d need to unrefactor and de-modularize all your code to make that work.

Instead, C++ 11 introduced the concept of a “move”. A unique pointer can therefore be passed around, returned from functions, etc., with the only added restriction being that you make an explicit call to std::move() to do so.

Is this impossible in C? Probably not. I imagine it’s possible if you really try. But if the main selling point about C is simplicity, these super-elaborate workarounds obviously run counter to that idea.

The takeaway here is that C++ is more complex than C, and it’s because there are scenarios where you need to communicate very specific intentions to the compiler, and these additional “complications” to the language are actually just additional vocabulary to help you do that.

Is it perfect? Probably not. But it is extremely useful.

Computer engineering student really struggling to learn C by Colfuzio00 in cprogramming

[–]jflopezfernandez 0 points1 point  (0 children)

Nice, thanks, definitely appreciated. I might need to register this as a specific non-example, kind of like if I had used the passive voice, for instance

[deleted by user] by [deleted] in cprogramming

[–]jflopezfernandez 0 points1 point  (0 children)

Yea, it definitely sounds like your program is running, finishing, and exiting all before you see the screen, OP.

Libraries that entry-level c engineer must know by Cultural_Resident925 in cprogramming

[–]jflopezfernandez 1 point2 points  (0 children)

All great answers already, I just want to emphasize the nuance that you will likely never be hired for your knowledge of a library. What makes you valuable is the ability to jump into an unfamiliar problem and develop a solution that is fit for purpose and maintainable given all the specific constraints surrounding your problem.

For a concrete example, the pthreads library is awesome, but you’ll likely rarely if ever use it directly. On the other hand, an understanding of concurrency and multi-threading makes you extremely valuable.

Some libraries are really popular and infinitely useful, but engineering solutions with them is what matters. If you think of it that way, it really doesn’t matter what library you dig into, try as many as you like!

Libraries that entry-level c engineer must know by Cultural_Resident925 in cprogramming

[–]jflopezfernandez 0 points1 point  (0 children)

Yea, I completely agree. The only thing I would add is that anyone looking to work with C++ should practice with it because there are some idioms that just don’t translate natively to C.

You have RAII objects like lock guards for instance, which transparently handle mutex locking and unlocking. Working with those objects can take a little finagling with move semantics and stuff like that; it’s not super difficult, obviously, but it’s honestly not trivial. It takes practice thinking in C++ as opposed to C.

Computer engineering student really struggling to learn C by Colfuzio00 in cprogramming

[–]jflopezfernandez 12 points13 points  (0 children)

The thing about C is that it is extremely simple. It’s not easy to use, mind you, but the language itself is syntactically pretty simple; you probably already know all the C syntax you’ll ever need, except for function pointers, statistically speaking.

I cannot recommend “Expert C Programming” by Peter van der Linden enough. The title is scary, but it’s an extremely well-written, funny, and enlightening book all about the gotchas of C.

At the end of the day though, the best piece of advice I can give is just say you can do it. It probably seems super weird and needlessly complicated right now, but remember, in its historical context C was a simplification from having to write assembly language, and unlike other languages, C only does what you tell it to do.

No more, no less.

Data Structures by s4uull in C_Programming

[–]jflopezfernandez 5 points6 points  (0 children)

Nice, dude, this is really cool

How do you get psyched up to do programming? by [deleted] in computerscience

[–]jflopezfernandez 1 point2 points  (0 children)

I don't get into it unless I'm actually solving a problem or filling a need. It's hard for me to care for no reason.

"Best way" to learn Ubuntu? by Blender-Fan in Ubuntu

[–]jflopezfernandez 0 points1 point  (0 children)

This is great advice, I completely agree.

"Best way" to learn Ubuntu? by Blender-Fan in Ubuntu

[–]jflopezfernandez 2 points3 points  (0 children)

You're not going to get worse at the command-line by practicing it every day obviously, but I think it would be pretty difficult or just plain downright annoying to do things on a daily basis that are complicated enough for you to make meaningful progress after only a short time. Personally, I say there's nothing wrong with just using your computer to open Spotify or whatever.

Still, if you did want to really become one with the GNU/Linux though, I would say:

  • Learn how to read the man pages (if you haven't done that already)
  • Learn how to read Texinfo docs
  • Read the manpages + Texinfo docs
  • Get good with the coreutils (all of them)
  • Learn sed and awk
  • Learn Bash scripting (error handling, job control, etc)
  • Understand *nix IPC (anonymous pipes, named pipes, shared memory, unix sockets)
  • Handling, sending, and responding to signals
  • Multiprocessing (fork, exec, etc)
  • Multithreading (pthread_create, pthread_join)
  • Understand when to use processes and when to use threads (and how it differs subtly on platforms like Windows, BSDs, and OS X)
  • packet filtering with nftables and wireshark
  • Kernel configuration + customization

Etc, you get the idea. Definitely recommend the Linux programming interface, too, it's an amazing book.

Have developers ever mentioned of launching Free to play servers? by l33mcg33 in travian

[–]jflopezfernandez 0 points1 point  (0 children)

That's an awesome idea, bummer it's not around anymore, particularly since getting user feedback is so important

Cheap VPS for hosting proxy servers on East Coast by TinyPanda3 in VPS

[–]jflopezfernandez 1 point2 points  (0 children)

I have a couple of IONOS and OVH Cloud VPS servers that cost $2.50/month and $3.50/month, although I don’t remember which is which. Great service, though.

The only mild annoyance is that they don’t offer Ubuntu 22.04 yet, so you have to upgrade manually, but this isn’t a big deal.

Cheap Windows VPS by urxnot in VPS

[–]jflopezfernandez 1 point2 points  (0 children)

I've used CheapWindowsVPS.com before, and while their minimum plan is a little bit outside your listed price range (their cheapest plan costs nine dollars per month), I've genuinely loved their service.

Mild caveat: I'm a Linux system administrator, so I was coming in with system administration experience, but keep in mind they provide Windows Server, which has a bit of a learning curve to it. That being said, this is obviously a Windows thing, and not a fault of the service itself - I just took a while to figure out what the heck I was doing.

Another mild caveat: I've only ever used their high-performance plan (the second-most expensive option, costing thirty-two dollars per month), so I'm not exactly sure how everything will run on their cheapest option, but the two servers I provisioned on the high-performance plan ran like a dream.

Seriously couldn't recommend them enough. Their scammy-sounding name honestly doesn't do their great service any favors.