Questions tagged [packing]

Use this tag for questions related to packing, which can extend from struct packing to grouping elements together.

In C, will prevent the compiler from adding padding to a struct, which will save some memory, but may affect access speed to the members of the struct (since it may not memory-aligned).

However, has a general meaning as well, when you want to group/cluster similar elements together.

347 questions
318
votes
11 answers

Structure padding and packing

Consider: struct mystruct_A { char a; int b; char c; } x; struct mystruct_B { int b; char a; } y; The sizes of the structures are 12 and 8 respectively. Are these structures padded or packed? When does padding or packing take place?
Manu
  • 5,534
  • 6
  • 32
  • 42
297
votes
7 answers

What algorithm can be used for packing rectangles of different sizes into the smallest rectangle possible in a fairly optimal way?

Ive got a bunch of rectangular objects which I need to pack into the smallest space possible (the dimensions of this space should be powers of two). I'm aware of various packing algorithms that will pack the items as well as possible into a given…
Fire Lancer
  • 29,364
  • 31
  • 116
  • 182
126
votes
1 answer

Why does git keep telling me it's "Auto packing the repository in background for optimum performance"?

Note: I don't think this is a duplicate of this question, which is talking about a non-background pack which hangs git with a subtly different error message. In one of my git repositories, each time I invoke (for example) git fetch, git…
Andrew Ferrier
  • 16,664
  • 13
  • 47
  • 76
40
votes
7 answers

use of the bitwise operators to pack multiple values in one int

Low level bit manipulation has never been my strong point. I will appreciate some help in understanding the following use case of bitwise operators.Consider... int age, gender, height, packed_info; . . . // Assign values // Pack as AAAAAAA G…
maxpayne
  • 2,479
  • 4
  • 28
  • 28
33
votes
5 answers

Packing different sized circles into rectangle - d3.js

I was trying to pack circles of different sizes into a rectangular container, not packing in circular container that d3.js bundled with, under d3.layout.pack. here's the layout I want to achieve: I've found this paper on this matter, but I am not a…
Hiroaki Yamane
  • 331
  • 1
  • 5
  • 4
31
votes
1 answer

Why doesn't C++ make the structure tighter?

For example, I have a class, class naive { public: char a; long long b; char c; int d; }; and according to my testing program, a to d are built one after another, like a------- bbbbbbbb c---dddd - means unused. Why does not C++…
Dante May Code
  • 11,177
  • 9
  • 49
  • 81
20
votes
4 answers

Packing rectangular image data into a square texture

I have N items of 2D image data that will be rectangular and I want to pack them into a single power of 2 texture as efficiently as possible. A simple non-efficient and naive implementation of an algorithm to pack these rects would be easy to whip…
TexturePacker
19
votes
3 answers

Given a target sum and a set of integers, find the closest subset of numbers that add to that target

I have a set of integers M and a target sum k. I want to find the subset of M that when added together is the closest to k without going over. For example: M = {1, 3, 5, 5, 14} k = 12 answer = {1, 5, 5} because 1 + 5 + 5 = 11 and there is no way…
17
votes
3 answers

Close-packing points in the plane?

Suppose that I have a complete, undirected graph G with a distance associated with each edge. The meaning of edge (u, v) having length l is "points u and v can't be any closer to each other than l." My goal is to lay the nodes of this graph out in…
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
17
votes
9 answers

C++ Data Member Alignment and Array Packing

During a code review I've come across some code that defines a simple structure as follows: class foo { unsigned char a; unsigned char b; unsigned char c; } Elsewhere, an array of these objects is defined: foo listOfFoos[SOME_NUM]; Later,…
Adam Holmberg
  • 7,245
  • 3
  • 30
  • 53
16
votes
1 answer

Pylint warning: Possible unbalanced tuple unpacking with sequence

I have a piece of Python code: def func1(): a=set() b = ','.join(map(str, list(a))) return b, [] def func2(): d = 1 …
user1659464
  • 313
  • 1
  • 3
  • 9
15
votes
4 answers

Packing arbitrary polygons within an arbitrary boundary

I was wondering if anybody could point me to the best algorithm/heuristic which will fit my particular polygon packing problem. I am given a single polygon as a boundary (convex or concave may also contain holes) and a single "fill" polygon (may…
Craig
  • 564
  • 1
  • 5
  • 20
15
votes
1 answer

packing algorithm in rtree in boost

Hi all I understand that if rtree is created with range values in boost it would use packing algorithm. I need an example of rtree using packing algorithm. Here is my code that uses quadratic algorithm using point = bg::model::point < int, 2,…
Prem
  • 355
  • 2
  • 17
15
votes
5 answers

Java Convert 4 bytes to int

i was wondering if the solution for this documented here is still the solution or is there any other way getting an int from 4 bytes? thank you. EDIT: im getting the byte[] from sockets .read EDIT: int recvMsgSize = in.read(Data, 0, BufferSize); if…
iTEgg
  • 8,212
  • 20
  • 73
  • 107
15
votes
3 answers

Algorithm putting point into square with maximal minimum distance

I'm stuck on this: Have a square. Put n points into this square so the minimal distance (not necessary the average distance) is the highest possible. I'm looking for an algorithm which would be able to generate the coordinates of all points given…
Mikulas Dite
  • 7,790
  • 9
  • 59
  • 99
1
2 3
23 24