What is sorting? What happens when something is "sorted"?

I know this question has been asked, at least here .

But there was no answer, at least not for me. There is a lot of talk about marshalling about interacting with unmanaged code, but what about sorting from one thread to another, as is usually the case in .NET.

It makes me ask, what is marshalling? When you give a definition of sorting, how would you define it so that it explains the case of interaction, as well as the cases when you "sort" between threads?

+60
multithreading definition marshalling language-interoperability
Apr 08 2018-11-21T00:
source share
6 answers

Computations often need to move data from one site to another and have no shared memory. Thus, one calculation sends a message containing data to another.

How is this data, if arbitrarily complex, sent in a message?

Marshalling is the process of converting a data field or a whole set of related structures into a serialized string that can be sent in a message. To output the binary code number, you can convert it to a hexadecimal digit string if the message format should be text. If the message contains binary data, the binary number can be converted to 4 low binary binary bytes and sent in this way. Pointers are more complicated; often you have to convert them to an abstract link (for example, "node number"), which does not depend on the actual memory locations.

Of course, if you "sort" the data, you should eventually "parse" what is the process of reading a sequential stream and restoring the transmitted data (structure).

Often the library uses (un) sorting procedures in the library that are used to achieve this goal, and sometimes there are even tools that will make all the calls needed for the (un) sorting routines to send / receive data.

+71
Apr 08 2018-11-21T00:
source share

Marshalling takes data in one form or another and translates it into a separate form. This is a very general term and is used in many places with minor differences in meaning.

For example, in .NET, the interaction layer, when you work with your own types of “marshals,” your data from the .NET type calls its own method into the appropriate form, then the “marshals” return the results.

As for "sorting" between threads - often you need the code to work in a different thread than the current one. For example, if you use Windows Forms, you cannot change the user interface element in the threadpool thread, so you will need to "marshal" the call back to the user interface thread. This is done by creating a delegate and passing the delegate back to the UI thread through Control.Invoke (which uses a rather sophisticated system to send it back to the appropriate synchronization context), which in turn launches the delegate in the UI thread for you.

+24
Apr 08 2018-11-21T00:
source share

The definition of Wikipedia is actually pretty good.

The general concept of marshalling is the same as “serialization:” moving from a view in memory (which in a sense is not like any representation - when something in memory just “exists”) to “hardcopy”, be it XML or maybe a binary stream or something like that. However, depending on what you are doing, it may also involve some kind of conversion or translation to the target format.

To sort processes: one thread does not just “call” another — data must be packed and “sent” from one thread to another. Marshalling is the process of packing this data (for example, data about the method you want to call and its parameters).

If you execute the interop command, you collect the method call and its parameters into a data structure that can be sent to the process / thread working with the COM component. This package must be in a format that the COM component can understand.

+11
Apr 08 2018-11-21T00:
source share

The way I understand marshaling is that it provides you with the ability to transfer data sequentially in various operating environments.

In the context of marshaling data from managed unmanaged code, this is more or less the same.

I have some data, like an array of integers or any data type of my choice, and I want to make it available for use in my C # code after my C ++ code performs some operations on it.

I can't just say, “Hey, this is where the array is, do what you want,” for C # code. An array of ints in C ++ may not be stored in the same way as in C #. Marshaling allows you to transfer this data in a manner that is independent of the environment so that both sides see the data equally accurately.

Another example is online. Usually you do not call it marshaling, but if you want to transmit it over the network, you should usually transmit it in such a way that the one who receives it interprets the data in the same way as you. Your computer might present the data in a small end order, and the other might represent it in ascending order.

tl; dr: Marshaling gives you the ability to sequentially present data in various operating environments

+4
Apr 08 2018-11-21T00:
source share

From Wikipedia - Marshalling (computer science) :

Marshalling (like serialization) is the process of converting an object's memory representation into a data format suitable for storage or transmission. It is commonly used when data must move between different parts of a computer program or from one program to another.

When calling an unmanaged function from .NET, marshalling is used to convert .NET data to data that an unmanaged function can use. For example, System.String based on Unicode, but this string may need to be converted to an ANSI string, which will be passed to the unmanaged function C.

For streaming processing, marshalling usually refers to transferring ownership of some data from one stream to another stream. For example, a program has two threads. The first stream reads data from the network, and the second stream calculates this data. After the network stream reads some data, it transfers (ie, "Marshals") the data to the computation stream for processing. This can be done by writing data to a queue shared between two threads.

Stream marching almost always involves synchronizing data that is sorted.

+3
Apr 08 2018-11-11T00:
source share

It is usually used in the context of "written in XML format", but it can be attributed to any format.

 2. To arrange, place, or set in methodical order. (from American Heritage® Dictionary of the English Language) 

So this means that you are ordering the data in the required methodological order / format. Often this is in XML format.

+1
Apr 08 2018-11-21T00:
source share



All Articles