洞悉事物如何在屏幕上打印(cout,printf)以及我在教科书上似乎找不到的真正复杂的事物的起源 [英] Insight into how things get printed onto the screen (cout,printf) and origin of really complex stuff that I can't seem to find on textbooks

查看:97
本文介绍了洞悉事物如何在屏幕上打印(cout,printf)以及我在教科书上似乎找不到的真正复杂的事物的起源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想知道这个,但仍然没有找到答案.每当我们使用"cout"或"printf"时,在屏幕上显示的精确程度如何?文本是如何显示出来的……(可能是一个模糊的问题,不管您给我什么东西,都行不通.).因此,基本上,这些功能是如何实现的...它是汇编语言吗?这带来了更多的问题,例如他们到底是如何实现openGl/directx函数的..

I've always wondered this, and still haven't found the answer. Whenever we use "cout" or "printf" how exactly is that printed on the screen?. How does the text come out as it does...(probably quite a vague question here, ill work with whatever you give me.). So basically how are those functions made?..is it assembly?, if so where does that begin?. This brings on more questions like how on earth have they made openGl/directx functions..

分解它人们分解它:)

推荐答案

这里是一种情况,缩写为:

Here's one scenario, with abbreviations:

  1. printfcout将字符放入用户程序地址空间中的缓冲区.
  2. 最后,缓冲区已满,或者printf要求尽早清空缓冲区.无论哪种方式,I/O库都将调用操作系统,该操作系统会将缓冲区的内容复制到其自己的空间中.
  3. 假设输出文件已绑定到终端,则操作系统将字符传递给终端应用程序.
  4. 终端应用程序决定,对于缓冲区中的每个字符,它都需要在屏幕上绘制像素.
  5. 终端应用程序设置像素绘制指令,并要求窗口管理器代表其执行此操作. (如今,在Unix上,这通常是X服务器.)
  6. 窗口管理器获取像素.如果窗口实际上在屏幕上可见,则窗口管理器将更新一个缓冲区(称为 frame buffer ),该缓冲区保存可见像素.然后,窗口管理器可能会通知操作系统,或更可能的是,窗口管理器与操作系统发生纠缠,它们正在共享相同的内存.
  7. 下次刷新屏幕时,硬件会在帧缓冲区中看到新的位,并以不同的方式绘制屏幕.
  8. Voilà ;!屏幕上有字符.
  1. printf or cout put characters into a buffer in the user program's address space.
  2. Eventually the buffer fills, or perhaps printf asks for the buffer to be emptied early. Either way, the I/O library calls the operating system, which copies the contents of the buffer to its own space.
  3. Supposing that the output file is bound to a terminal, the operating system delivers the characters to the terminal application.
  4. The terminal app decides that for each character in the buffer, it needs to paint pixels on the screen.
  5. The terminal app sets up pixel-painting instructions, and it asks a window manager to do this on its behalf. (On Unix these days this is usually an X server.)
  6. The window manager takes the pixels. If the window is actually visible on the screen, the window manager then updates a buffer (called the frame buffer) which holds the visible pixels. The window manager may then notify the operating system, or more likely, the window manager is in cahoots with the operating system and they are sharing the same memory.
  7. The next time the screen is refreshed, the hardware sees the new bits in the frame buffer, and it paints the screen differently.
  8. Voilà! You have characters on the screen.

这只熊跳着舞真是太神奇了.

It is amazing that the bear dances at all.

这篇关于洞悉事物如何在屏幕上打印(cout,printf)以及我在教科书上似乎找不到的真正复杂的事物的起源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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