Results 1 to 10 of 42

Thread: pascal and learning 3d

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    I don't know exactly how it goes, but i tested a bit too after your comment. TRGB2 is indeed 3 bytes for some reason.

    But these are both 8 bytes, and 5 if packed. Same with Lazarus and Delphi.
    Code:
    TRecord1 = record
      a: single;
      b: byte;
    end;
    
    TRecord2 = record
      b: byte;
      a: single;
    end;
    So it doesn't matter if the value is last one. Having only 1 variable type in record seems to be special case, that is not adding any padding.
    Last edited by User137; 30-11-2012 at 04:48 PM.

  2. #2
    By the way, I'm mistaken regarding packed being deprecated, after checking manuals again, I did not find any references to it. I remember reading about it somewhere since release of XE 2, but perhaps got it confused with something else. Sorry.

  3. #3
    Packed records or packed arrays are used when you wnat to decrease the memory needed to store theese. Packed comes into effect if the records or arrays contains variables which by default aren't alined to 2, 4, 8 bit alingment. Default alingmnets for variables differ by variable type and is defined so that it offers optimized performance for working with theese variables.
    But with the usage of Packed command you can override theese default alignments and pack data closely together thus lowering the memory consumption. Doing so also decreases the peformance of working with theese variables a bit since they are no longer optimally aligned. Unles you are using large record or large array difference in performance probably won't even be noticable.

    Using of Packed records is sometimes necessary if you are sending some data to another application which is developed with different compiler since not all compilers use same data aligment for reaching optimal performance. In some cases using non packed records can cause for data in other program to be read incorectly.
    So always make sure to check program documentation as of which type of records it can recieve. Same goes for varios API functions.

  4. #4
    This memory optimization gave me a slight headache today. Was trying to use dynamic array of singles as source for vbo data and result was trash. Later it turned out that there's no such problems with static array. Can I force dynamic array to be bit aligned(or whatever its the problem)? using 'packed array' didn't help and Id' rather have a buffer that can grow if needed.

  5. #5
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    I have been using dynamic arrays with no problem, never had to use pack arrays, just arrays of pack records. what are you tring to pass ?

  6. #6
    turned out that I was dereferencing a pointer in a wrong way
    with static array it was just:
    glBufferData(GL_ARRAY_BUFFER,x,buffer,GL_STATIC_DR AW);
    and with dynamic should be:
    glBufferData(GL_ARRAY_BUFFER,x,@buffer^[0],GL_STATIC_DRAW);

    where 'buffer' is a pointer for that array type.

    ps: it liiveees!!
    Last edited by laggyluk; 01-12-2012 at 11:42 PM.

  7. #7
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    there is no way the compiler would change the layout for dynamic vs static that would break the compatibilty of the two. my guess is that you are miscalculating the size some where and the data isn't making it to the final destination. Edit:guess Iwas too slow, so you got it, looks good.
    Last edited by Carver413; 02-12-2012 at 12:20 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •