메모리<->cpu간 작업시간을 최소로 단축시킬수있는 작업단위는 몇비트인가요??

k1d0bus3의 이미지

구조체 링크드리스트(or 배열)을 만들어서, 메모리 <-> cpu간 r/w을 하려고 합니다.

제가알기로는 cpu는 32bit단위로 처리하고, 메모리 입출력단위는 8bit로 알고있습니다.

가능한한 메모리 <-> cpu간 작업처리시간을 줄이려면,(메모리에있는 구조체의 각멤버필드를 read/write하려고 합니다)

이때 구조체전체크기나 각각의멤버필드를

32bit의 배수에 맞추는게 유리합니까? 8bit의 배수에 맞추는게 유리합니까?

구체적으로 말하자면....

다음의 구조체 멤버들의 자료형은 어떡게 선언하는게 최선일까요?

비트필드로 선언하는게 유리합니까?

struct person{
어떤자료형? dataA; (크기는최소3bit이상되야함)
어떤자료형? dataB; (크기는최소10bit이상되야함)
struct person* link; (32bit)
};

ddoman의 이미지

Quote:

이때 구조체전체크기나 각각의멤버필드를
32bit의 배수에 맞추는게 유리합니까? 8bit의 배수에 맞추는게 유리합니까?

struct의 사이즈는
컴파일러가 해당 architecture의 word size의 배수로, 가장 자연스러운 사이즈로 알아서 조정하여 줍니다.

그래서 그렇게 하지 말아달라고 컴파일러에게 지시하는 전처리 명령어들이 있습니다. 가령 #pragma pack.
검색해보시면 관련 문서 많이 나옵니다.

==================
메모리 접근은 word 단위로 하는것이 가장 자연스럽습니다: http://en.wikipedia.org/wiki/Word_%28computing%29
각 architecture 마다 word의 사이즈는 다를수도 있습니다.
자세한 설명은 위키페이지의 설명 참고하세요.

하지만...속도를 위해서라면
이런것보다, 어떻게 하면 cache-friendly 코드를 만들까 생각하는게 훨신 생산적입니다.
메모리는 너무너무너무너무 엄청나게 느립니다. 그래서 OS는 메모리접근의 횟수를 최대한 적게하려고 노력합니다.

메모리 접근이 빈번하면 전반적인 시스템이 엄청느려집니다.
cache-hit rate가 1%만 떨어져도 엄청난 속도 저하가 나타납니다.

또한, 메모리 fragmentation 을 막기위해 메모리 풀같은걸 구현하여 사용하는게
훨신 영양가 높은 방법입니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.