本文介绍了Java中共享内存的任何概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

AFAIK,Java中的内存基于堆,内存被动态地分配给对象,并且没有共享内存的概念。

AFAIK, memory in Java is based on heap from which the memory is allotted to objects dynamically and there is no concept of shared memory.

如果没有概念共享内存,然后Java程序之间的通信应该是耗时的。在C中,与其他通信模式相比,通过共享内存进行进程间通信的速度更快。

If there is no concept of shared memory, then the communication between Java programs should be time consuming. In C where inter-process communication is quicker via shared memory compared to other modes of communication.

如果我错了,请纠正我。另外两个Java程序相互交流的最快方式是什么。

Correct me if I'm wrong. Also what is the quickest way for 2 Java progs to talk to each other.

推荐答案

由于没有正式的API可以创建一个共享内存段,你需要求助于一个帮助库/ DDL和JNI来使用共享内存让两个Java进程相互通信。

Since there is no official API to create a shared memory segment, you need to resort to a helper library/DDL and JNI to use shared memory to have two Java processes talk to each other.

实际上,这是由于Java支持线程,因此很少出现问题,因此您可以在同一个Java VM中运行两个程序。那些将共享相同的堆,因此通信将是即时的。此外,由于共享内存段出现问题,您无法获得错误。

In practice, this is rarely an issue since Java supports threads, so you can have two "programs" run in the same Java VM. Those will share the same heap, so communication will be instantaneous. Plus you can't get errors because of problems with the shared memory segment.

这篇关于Java中共享内存的任何概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 11:02