I’m sure many of you watching some tutorial videos on YouTube. I do. And there are different people who do the talking. Some are talking fast, and some are talking slow. Some of them put quite condensed information and some put a lot of “water” in their talk.
For quite some time I was watching on regular speed, but a few years ago I found really nice advice to use faster speeds. I tried 1.25 initially and it was amazing. If you have a tutorial that is one hour long, you can finish watching it in 48 minutes and save 12 minutes of your life. 1.25 speed does not distort the voice much and it is almost the same as
[...Read More]
Some time ago, I, like many of you moved to Visual Studio 2022. It works great with C# and eventually, I decided to move C++ activities to VS 2022 as well. After I installed everything, I created C++ Console Application and I try to compile it. To my surprise, it didn’t work, and got the following message:
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.32.31326\include\yvals.h(12,10): fatal error C1083: Cannot open include file: 'crtdbg.h': No such file or directory
After some research, I found an article that helped me. For some reason, there is an invalid path to Windows SDK in the registry. To fix this issue you need to go to this registry key:
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots
And change
[...Read More]
For many years, when I get a new notebook, I wipe it out and install a fresh version of Windows. There are multiple reasons for that:
- To instantly get rid of unwanted software that takes valuable disk space
- To avoid unwanted software draining your battery and heating your notebook (especially in the summertime)
- To remove potential conflicts with the installed software. For example, a trial version of Microsoft Office conflicts with another office package. Even removing Microsoft Office does not help
- To avoid problems with an installed antivirus solution. The best example is McAfee. I spent weeks or even months of my life fighting with it. It is the worst antivirus on the market. Built-in Windows Defender is much better and provides better protection
[...Read More]
I think many of you a familiar with function SetWindowsHookEx. It is quite useful function, and we use it in a lot of places in our software. But recently I found interesting issue: if exception is raised in hook function, then Windows will terminate your application with status code 0x C000041D STATUS_FATAL_USER_CALLBACK_EXCEPTION. But there is one caveat: if you run application from debugger, Windows will not terminate application and will just suppress exception. So, if you have encounter that exception as developer, you may think that everything is correct, but when end user will run your application – application will crash.
I work primarily with languages that have native support for exceptions and it feels kind of wrong. There is
[...Read More]
I did some research on this topic and I decided to share my findings.
First reason: Standards
On most 32 bits systems type short is 2 bytes long, type int is 4 bytes long. But there are also standards.
According to C90 standard:
sizeof(short) <= sizeof(int) <= sizeof(long)
According to C99 standard:
sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)
If
int size will 8 bytes long then there will be no type that it is 4 bytes
long because due to standard,
long type should be at least the same size as
int type. It is possible to make
short type 4 bytes long
[...Read More]
About 5 years ago, we moved our main application to 64-bit. And we quickly discovered one pattern that was everywhere and in many different languages: converting pointers to 4-byte integers and back. Here is one of such examples is C++ code:
void* address;
…
(void*)(((unsigned int)address) + 1)
It was working in 32-bit systems because pointer and integers are exactly the same size and there is no data loss. But during transition to 64 bits, decision was made to keep integer 4 bytes in size. At least on systems I know of.
As result, if you run code above for address that is greater than max int, you will get invalid address. But until address is in first
[...Read More]
Previous part is here. This post will explain, how to restart your web site at specific intervals without returning errors to clients. You can scroll to solution, if you are no interested in my thoughts and to see what I try.
Thoughts and research
As I mentioned in
this post, I decided to restart my web site periodically to avoid out of memory issue. And I would like to mention that it wasn’t easy to do. Obviously, restarting web site is super simple and all you need is to restart its service. But that means that your web site will be unavailable for some time. Depending on size of the web site, we are talking about seconds or
[...Read More]
Some time ago, I wrote series of posts on how to run .NET Core app on AWS Lightsail Linux instance. Everything worked nice but sometimes, about once per month my web site stopped responding. And I cannot connect to my instance at all to diagnose that issue. All I can do is just restart my AWS instance. At the beginning I thought it could be AWS issue, or perhaps some issues in .NET. I updated everything I can, but problem persists. And when it happened last time, I decided to check kernel logs and I found this:
Feb 10 07:31:18 ip-1-2-3-4 kernel: [1512878.216567] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/system.slice/www.example.com.service,task=dotnet,pid=511,uid=1001
Feb 10 07:31:18 ip-1-2-3-4 kernel: [1512878.216597] Out of memory: Killed process 511 (dotnet) total-vm:3007440kB, anon-rss:105260kB, file-rss:0kB, shmem-rss:0kB, UID:1001 pgtables:712kB oom_score_adj:0
Feb 10 07:31:18 ip-1-2-3-4 kernel: [1512878.241642] oom_reaper: reaped process 511 (dotnet), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB
[...Read More]
Recently I was asked to check why one of our applications crashes when it calls CreateNamedPipe function. Everything works fine in the x64 version, but the x86 version crashes. There are no differences in the code between x86 and x64 and they compiled the same.
Let’s see how CreateNamedPipe defined in our code:
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern SafePipeHandle CreateNamedPipe(string lpName, uint dwOpenMode,
uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize,
uint nDefaultTimeOut, SECURITY_ATTRIBUTES securityAttributes);
and here is how it called:
SafePipeHandle safeHandle = CreateNamedPipe(
$@"\\.\pipe\{pipeName}",
cPipeAccessDuplex |
cFileFlagOverlapped,
cPipeTypeMessage |
cPipeWait,
cPipeUnlimitedInstances,
nOutBufferSize: 0,
nInBufferSize: 0,
cWaitForever,
securityAttr);
Everything looks correct. I checked flags, compared them with
[...Read More]