What is object marshalling?

后端 未结 10 903
后悔当初
后悔当初 2020-12-13 01:42

I have heard this concept used frequently, but I don\'t have a really good grasp of what it is.

相关标签:
10条回答
  • Marshalling is the process of transforming the memory representation of an object to a data format that could be stored or transmitted. It's also called serialization (although it could be different in certain contexts). The memory representation of the object could be stored as binary or XML or any format suitable for storage and/or transmission in a way that allows you to unmarshal it and get the original object back.

    For an example of usage, if you have some online game with a client and server components and you wanted to send the player object containing player stats and world coordinates from the client to the server (or the other way around), you could simply marshal it at the client, send it over the network, and unmarshal it at the other end and it would appear for the server as if the object was created on the server itself. Here's a ruby example:

    srcplayer = Player.new
    # marshal (store it as string)
    str = Marshal.dump(srcplayer)
    #unmarshal (get it back)
    destplayer = Marshal.load(str)
    
    0 讨论(0)
  • 2020-12-13 02:14

    I beg to differ, Wikipedia is pretty clear on this.

    In computer science, marshalling (similar to serialization) is the process of transforming the memory representation of an object to a data format suitable for storage or transmission. It is typically used when data must be moved between different parts of a computer program or from one program to another.

    http://en.wikipedia.org/wiki/Marshalling_(computer_science)

    0 讨论(0)
  • 2020-12-13 02:16

    Marshalling is the conversion between a native type in c++ (HTMLElement, const wchar_t*) and the internal runtime representation that the virtual machine library in c++ uses (JSObject, MonoString etc.) to represent the virtual type / managed type that is visible to JS/C# etc. scripts running on the virtual machine (HTMLElement, System.String). P/Invoke performs automatic marshalling. Passing a System.String to a native call using P/Invoke causes a const wchar_t* to be passed to the native call as automatic marshalling takes place. When you use internal calls however, it will be passed as a MonoString, which the c++ function will have to marshal itself and then marshal whatever it needs to return to an internal runtime return type. Only blittable types don't need to be marshalled when using internal calls, for instance, int, which is a System.Int32 is passed as a gint32, which is just an int.

    0 讨论(0)
  • 2020-12-13 02:17

    People have defined marshalling quite clearly already, so I'll skip the definition and jump to an example.

    Remote procedure call uses marshalling. When invoking remote functions you will have to marshall the arguments to some kind of standard format so it can be transport across the network.

    0 讨论(0)
  • 2020-12-13 02:20

    In a very generic sense in programming it simply means taking data in one format and transforming it into a format that is acceptable by some other sub-system.

    0 讨论(0)
  • 2020-12-13 02:21

    Basically it's an expression for generically transforming an object (or similar) into another representation that (e.g.) can be sent over the wire or stored to disk (typically string or binary stream. The opposite, unmarshalling, describes the opposite direction of reading the marshalled representation and re-creating an object or whatever in-memory-structure existed earlier.

    Another current everyday example is JSON

    0 讨论(0)
提交回复
热议问题