大会内存分配 [英] Assembly memory allocation

查看:175
本文介绍了大会内存分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习汇编语言的,我需要的东西澄清。请纠正我,如果我错了,任何的这个,因为我不知道很多关于组装。

I am trying to learn assembly language and I need clarification on something. Please correct me if I am wrong on any of this since I don't know much about assembly.

所有的教程我看有一个分配给一个内存地址如 0×0000 汇编程序的变量,我可以理解,你必须手动组装分配的内存地址,但你怎么知道是干什么用的地址?

All the tutorials I watch have the variables of assembly programs assigned to a memory address like 0x0000, and I can understand that you must manually assign memory addresses in assembly, but how do you know what address to use?

显然,这是有道理的在最低的内存地址可能启动,但如果你分配变量大于内存大可在 0×0000 是什么?将有问题的变量跑过来 0×0001 0×0002 ?如果那样那不是乱了其他变量分配具有类似编号的空间(或者是你不应该赋予它们接近)?

Obviously it makes sense to start at the lowest memory address possible, but what if the variable you are assigning is larger than the memory available at 0x0000? Would the variable in question run over to 0x0001 or 0x0002? If it did wouldn't that mess up other variables assigned spaces with similar numbering (or are you not supposed to assign them that close)?

如果我有两个程序在同一时间汇编语言编写的运行(在一个现代操作系统),我已经在这两个程序中使用同样的内存地址,与其他将一个程序冲突,或者做操作系统只是分配可用内存地址,不管什么实际写入的程序?

If I have two programs written in assembly running at the same time (in a modern OS) and I have used the same memory addresses in both programs, will one program conflict with the other, or does the OS just assign an available memory address regardless of what was actually written in the program?

关于这个问题的任何信息都是AP preciated。

Any information on the subject is appreciated.

推荐答案

这个问题的答案你问的第二部分(上最先进的操作系统)是虚拟内存。

The answer to the second part of you question (on most modern OSs) is virtual memory.

您开始在与物理存储器中的硬件层。这就是你其实可以用手指戳东西。这是操作系统所看到的。操作系统让您在称为虚拟内存的抽象运行的进程。

You start at the hardware layer with physical memory. That's the stuff you can actually poke with your finger. This is what the operating system sees. The operating system lets you run processes on an abstraction called virtual memory.

每个进程都有自己的虚拟内存空间。因此,它可以pretend,它是唯一的过程中运行,它拥有吨的内存。然后,每次访问内存时,您提供的虚拟地址,被映射到物理地址。操作系统保留其虚拟地址被映射到实际的物理地址在RAM中的表。通常这是一些特殊的硬件性能做的原因,以及(MMU的,内存管理单元),但你可以做到这一点在软件100%了。

Each process gets its own virtual memory space. So it can pretend that it's the only process running, and it has tons of memory. Then each time you access memory, you supply a virtual address, which gets mapped to a physical address. The operating system keeps a table of which virtual address gets mapped to which actual physical addresses in RAM. Typically this is done with some special hardware as well (an MMU, memory management unit) for performance reasons, but you could do it 100% in software too.

所以,当你在你的程序说0x000的,这是一个虚拟地址。当你读或写它被翻译成计算机的物理地址。因此,在另一个过程中,同样的虚拟地址0x000的映射到不同的物理地址。该系统让你写你的程序不知道多少RAM究竟如何是可用的,或者什么解决你的程序将被装入。它还$ P $捣毁从属于另一个程序存储器pvents程序。

So when you say 0x000 in your program, that's a virtual address. It gets translated into a physical address by the computer when you read or write. So in another process, the same virtual address 0x000 maps to a different physical address. This system lets you write your program without knowing exactly how much RAM is available, or what address your program will be loaded into. It also prevents your program from trashing memory that belongs to another program.

对于第一部分,绝对。不同类型的数据采取不同的内存。你要知道,当你布置你的数据结构,你需要多少空间。还有字节对齐问题,要记住。多字节数据类型(例如浮点数)通常具有在该整除由2或4或它需要存储一个浮动的字节数的地址开始 - 它是处理器或RAM的要求。所以,你不能只是紧缩所有的数据一起,之后的下一个字节,你必须打好它以特定的顺序一样,如果你希望尽量减少未使用的内存一个拼图的碎片装配在一起。

As for the first part, absolutely. Different types of data take different amounts of memory. You have to know how much space you need when you lay out your data structures. There are also byte-alignment issues to keep in mind. Multi-byte data types (eg floating point numbers) often have to start at an address that is divisible by 2 or 4 or the number of bytes it takes to store a float -- it's a requirement of the processor or the RAM. So you can't just crunch all your data together, one byte after the next, you have to lay it out in a specific order like fitting together the pieces of a puzzle if you want to minimize unused memory.

这篇关于大会内存分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆