Skip to content

Instantly share code, notes, and snippets.

@breezhang
breezhang / tools.md
Last active August 29, 2015 13:55
windows memory dbg

###Microsoft's ASLR is weird

So what is ASLR? In short, when you boot a Windows Vista Beta 2 computer, we load system code into different locations in memory. This helps defeat a well-understood attack called “return-to-libc”, where exploit code attempts to call a system function, such as the socket() function in wsock32.dll to open a socket, or LoadLibrary in kernel32.dll to load wsock32.dll in the first place. The job of ASLR is to move these function entry points around in memory so they are in unpredictable locations. In the case of Windows Vista Beta 2, a DLL or EXE could be loaded into any of 256 locations, which means an attacker has a 1/256 chance of getting the address right. In short, this makes it harder for exploits to work correctly.

stack say

This is by design. Normally, Windows selects a preferred base address for an ASLR DLL when the DLL is first loaded, and then it keeps using that address until the system is rebooted. That way the DLL will be mapped at the same address in every pro

@breezhang
breezhang / Performance.md
Last active August 29, 2015 13:55
.NET Garbage Collector

###Improving .NET Application Performance and Scalability

Performance

@breezhang
breezhang / ngen.md
Last active August 29, 2015 13:55
Improving Launch Performance for Your Desktop Applications
@breezhang
breezhang / list.md
Last active August 29, 2015 13:55
windows and .net

.NET Framework 1.1: Windows Server 2003

.NET Framework 2.0: Windows Server 2003 R2

.NET Framework 3.0: Windows Vista, Windows Server 2008

.NET Framework 3.5 SP1: Windows 7, Windows Server 2008 R2

.NET Framework 4.0: Windows 8

@breezhang
breezhang / ms say no.md
Created February 1, 2014 07:01
get size of a managed object 85k? ...

There is no real way to know how much memory the object is using. The hashtable itself takes up some space. Each key will take up additional space (not part of the hashtable) and each value has its own set of space. If any of these have children then the children are separate as well.

The sizeof keyword in C# can be used to find the size of any value type but requires the use of unsafe code for anything other than PoDs. The Marshal.SizeOf method can be used to calculate the unmanaged size of an object but it will not handle the various subobjects mentioned earlier. The only way to determine the actual memory used would be to walk every object and every child object referenced. An alternative would be to serialize the binary object out to a binary formatter. This would give you a close approximation of the binary size but not necessarily the actual memory size.

You can use a profiler to get a better idea of the memory usage of an object but you can't do this programmatically very easily

@breezhang
breezhang / a.md
Last active August 29, 2015 13:55
DPI PPI defined

4

###DPI measurement in monitor resolutio

Monitors do not have dots, but do have pixels; the closely related concept for monitors and images is pixels per inch or PPI. Old CRT type video displays were almost universally rated in dot pitch, which refers to the spacing between the sub-pixel red, green and blue dots which made up the pixels themselves. Monitor manufacturers used the term "dot trio pitch", the measurement of the distance between the centers of adjacent groups of three dots/rectangles/squares on the CRT screen. Monitors commonly used dot pitches of 0.39, 0.33, 0.32, 0.29, 0.27, 0.25, or 0.22 millimetres (mm, 0.0087 in). LCD monitors have a trio of subpixels, which are more easily measured.

DPI measurement in printing

@breezhang
breezhang / a.md
Last active August 29, 2015 13:55
CQRS (CQRS means Command Query Responsibility Segregation)

Martin Fowler wiki

The fundamental idea is that we should divide an object's methods into two sharply separated categories:

◾ Queries: Return a result and do not change the observable state of the system (are free of side effects)

◾ Commands: Change the state of a system but do not return a value.

Commands - change the state of an object or entire system

@breezhang
breezhang / Event Sourcing.md
Created February 3, 2014 13:24
Event Sourcing defined

###Event Sourcing

Capture all changes to an application state as a sequence of events.

We can query an application's state to find out the current state of the world, and this answers many questions. However there are times when we don't just want to see where we are, we also want to know how we got there.

Event Sourcing ensures that all changes to application state are stored as a sequence of events. Not just can we query these events, we can also use the event log to reconstruct past states, and as a foundation to automatically adjust the state to cope with retroactive changes.

@breezhang
breezhang / a.md
Created February 4, 2014 12:08
.net Event memory leak

p

If the source object has a longer lifetime than the listener, and the listener doesn't need the events anymore when there are no other references to it, using normal .NET events causes a memory leak: the source object holds listener objects in memory that should be garbage collected.

@breezhang
breezhang / list.md
Last active August 29, 2015 13:56
DDD

pic

Entity

“This is my Entity, there are many like it, but this one is mine.”

The key defining characteristic of an Entity is that it has an Identity – it is unique within the system, and no other Entity, no matter how similar is, the same Entity unless it has the same Identity.

For example, consider a Person concept. If I have two Person objects, with the same Name, are they same Person? Bob Smith from Cheyenne, Wyoming and Bob Smith from Tallahassee, Florida might not agree. A popular gimmick I’ve seen is interviewing a Person with a famous name (but different identity). So if Name isn’t a Person’s distinguishing attribute, what is? Address? Social Security Number? Not for non-US citizens, what about a Kiwi Bob Smith?