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
-1
votes
0 answers

Finding the optimal arrangement of squares inside a bigger square

lets say the sides of the big square are 50 units. i want to fit as much 3x3 and 2x2 squares inside of it as possible with the condition that N2x2=0.7 N3x3 I tried the sat solver in python but the computing time gets insane with just a 20x20 grid…
Purgatory
  • 1
  • 1
-1
votes
1 answer

Find the closest combination of items to the requirements

So my problem is a little bit like knapsnack problem but with a bit of difference. Let's say I went to shopping and I am obliged to buy things that meet the requirements or the closest I can get (over the requirement or lower). For a better…
taha boud
  • 1
  • 2
-1
votes
2 answers

Unexpected value after type casting in c

I was implementing the code for sending data through a raw socket. As part of that, I have to construct an IP packet. But I am facing the problem as explained below using a sample program. #include struct iph { unsigned char ihl:4; …
shafeeq
  • 1,499
  • 1
  • 14
  • 30
-1
votes
1 answer

Can someone please explain the results returned by 'sizeof' in this code

I don't undertand the output shown below. I know that whenever a virtual function is present it creates a vptr but still the size printed is more than I would expect: #include using namespace std; class Base { int x; int y; int…
Pritul Dave
  • 189
  • 1
  • 11
-1
votes
3 answers

Determine struct size, ignoring padding

I receive datagrams through a network and I would like to copy the data to a struct with the appropirate fields (corresponding to the format of the message). There are many different types of datagrams (with different fields and size). Here is a…
martinkunev
  • 1,364
  • 18
  • 39
-1
votes
2 answers

C++ - cstyle structure/class packing pertinent?

Context I primirarly code in C. Trying c++. Not good enough with assembly to tell myself. But improving. Questions Do struct AND classes benefit from structure packing in c++ or is it only a c'ish thing? Do c++ add lot of magic? Will the private /…
Larry
  • 1,735
  • 1
  • 18
  • 46
-1
votes
4 answers

In java is it possible to pack a integer number that is expected not to be negative & be final (not overflow) into a short?

"Unsigned int" into a short and back. Is this possible? How to do it if so? Grrrr. I forgot how signed numbers are implemented. The question makes no sense. Thanks anyway. I was going to downvote myself, you can do it instead.
i30817
  • 1,356
  • 2
  • 13
  • 26
-1
votes
1 answer

Packing Circles inside a Circle

Given unit circle, and a set of M smaller circles of radius r. Find the maximum radius of the smaller circles that allows them all to fit inside the unit circle without overlap. I have the following circles packing in polygon example link I want…
-1
votes
2 answers

How can I build up the densely packing spheres, starting from a single one, in C++?

Let's assume that I start out with a single sphere of a defined radius R, and an array of three elements, containing the cartesian coordinates: double vecpos[3]; vecpos[0]= 0.0; vecpos[1]= 0.0; vecpos[2]= 0.0; double radius= 5; Now, I would like to…
Mark Anderson
  • 2,399
  • 3
  • 15
  • 21
-2
votes
3 answers

Trying to create a word count function

I'm trying to create a function: word_count("I do not like it Sam I Am") gets back a dictionary like: {'i': 2, 'do': 1, 'it': 1, 'sam': 1, 'like': 1, 'not': 1, 'am': 1} I've no idea how to begin.
-2
votes
1 answer

How can I model the Circle packing problem with pyomo?

Circle packing problem in a circle container with minimal radius
-2
votes
1 answer

How to Pack two executables into one executable, then extract and run them?

In Windows, what software is there for me to use so I can pack two executable files into one other executable, and then how do I make this other executable extract the two executables and run them both at the same time ? In other words, how do I…
-2
votes
1 answer

Timetable events packing

I'm working on timetable for school purposes. I receive time-ordered list of events and my goal is to draw them on timeline. The problem is that some event overlaps another (as shown on the picture below). What I want to do is to "pack" this events…
-2
votes
1 answer

How to calculate at runtime the maximum value allowed before datatype rollover?

I have the following structure: struct Some_Struct { uint32_t a; int16_t b; uint8_t c; }; struct Other_Struct { uint32_t a; uint32_t b; uint32_t c; }; The variable size is being calculated as such: uint32_t size =…
Zhro
  • 2,546
  • 2
  • 29
  • 39
-2
votes
2 answers

How to declare structures in C to avoid structure corruption?

I have a similar problem like this question and my problem was solved similar to this answer but I can't understand what caused this issue. I have three structures File, Line and Buffer declared in app.h. typedef struct File { FILE *fs; char…
ziggurat
  • 92
  • 7
1 2 3
23
24