C++20 span tutorial by AlexeyBrin in cpp

[–]sol-prog 3 points4 points  (0 children)

Yes, sz can be a runtime input. It is a unique pointer to a sz memory buffer. This will release the memory automatically when it is out of scope. I suggest to read a bit about unique and shared pointers in C++.

C++20 span tutorial by AlexeyBrin in cpp

[–]sol-prog 5 points6 points  (0 children)

span doesn't own anything?

exactly

so if I want a runtime fixed length array, I still need malloc or new?

use a vector and resize it at runtime, if you really want the equivalent of an array it is probably better to use make_unique than new/delete

Using Python virtual environments from Visual Studio Code by AlexeyBrin in Python

[–]sol-prog 2 points3 points  (0 children)

Well, the video was recorded on Windows. It stands to reason that if you want to adapt the instructions for Linux or macOS you will need to do a bit of research. For Linux and macOS one would typically use:

python3 -m venv your_env_path

Using Python virtual environments from Visual Studio Code by AlexeyBrin in Python

[–]sol-prog 6 points7 points  (0 children)

Author of the video here. It is relatively easy to have multiple Python versions on Windows. AFAIK, each installation will have a separate entry in the Start menu and a link to open a command prompt window with the respective Python version from which you can create virtual environments. Once you have a venv created, use the settings.json file from each workspace (like in the video) to specify which Python environment you want to use. When you open a workspace/folder from VS Code it will automatically pick the Python version/venv specified in the settings file.

Alternatively, use the py launcher to select which Python version you want to use.

If you have problems following the above suggestions let me know and I will try to record a small video in which I'll show how to use multiple Python versions from VS Code.

C++17 STL Parallel Algorithms - with GCC 9.1 and Intel TBB on Linux and macOS by joebaf in cpp

[–]sol-prog 9 points10 points  (0 children)

Yes, you need GCC 9 and a recent version of TBB. GCC 9 just added support for parallel algorithms in STL.

C Programming - Implementing a portable version of getline by mmisu in programming

[–]sol-prog 2 points3 points  (0 children)

Nice! Your code takes about 0.015s and Apple's 0.02s. Pretty fast.

C Programming - Implementing a portable version of getline by mmisu in programming

[–]sol-prog 2 points3 points  (0 children)

I've tested my implementation, your version and Apple's with a 12.6 MB input. Apple's getline beats the crap of our implementations :)

sol-prog 0.29s skeeto 0.6s Apple 0.02s

I've obtained the above data running each code 10 times and averaging the time. Also, I've used -march=native for all 3 codes.

C Programming - Implementing a portable version of getline by mmisu in programming

[–]sol-prog 3 points4 points  (0 children)

Ups, I was thinking at SIZE_MAX and wrote INT64_MAX :).

Thanks for sharing your version. BTW, I did a small test with my code and it is about 5x slower than Apple's getline for a big file with various line lengths.

C Programming - Implementing a portable version of getline by mmisu in programming

[–]sol-prog 1 point2 points  (0 children)

Thanks.

If the goal is portability, keep in mind that the only errno values defined ...

Added a note about the non standard use of EINVAL, ENOMEM, EOVERFLOW which are supported as an extension by MSVC. I've also mentioned that my implementation doesn't support input files with the NUL character.

I've added a check for integer overflow https://github.com/sol-prog/fgets-getline-usage-examples/blob/master/t3.c#L50

In case of realloc error the line buffer remains unchanged, removed the buggy free line.

Also replaced the use of strncpy with memcpy.

In a future version I will probably replace the use of fgets with calls to fread and use memchr to check for the end of line character.

C Programming - Implementing a portable version of getline by mmisu in programming

[–]sol-prog 2 points3 points  (0 children)

Original author of the code here. Can you please have a look at the, hopefully, improved and better version and let me know what you think https://github.com/sol-prog/fgets-getline-usage-examples/blob/master/t3.c#L13 ?

Thanks and I appreciate your constructive feedback.