让父div的宽度等于最宽的子元素/ div(Getting Parent div's width to equal widest Child element/div)
据我所知,如果未定义div的宽度和高度属性,则父div将等于排列的子元素宽度和高度属性的结果(统称分别)。
我目前的设置是这样的:
<div> //container <div> //list of each element <div> // element 1 ... children comprised of on SVG and a few other divs </div> <div> // element 2 ... children comprised of on SVG and a few other divs </div> <div> // element 3 ... children comprised of on SVG and a few other divs </div> …etc… </div> </div>
我的问题是元素div的
width
s没有正确设置(或更新)。 div的宽度应该是子SVG的宽度(因为它是最宽的),div的高度应该是子div的高度(其中2个)和SVG的高度。这是这个例子的小提琴 。 您会注意到栏示例正在被切断。 这个div的计算宽度是300,尽管它的SVG更大(拖动以查看剩余部分)
JQ-UI正在发挥作用,因此在用户操纵表示的大小后,其他人将重新渲染自己。 如果我们可以找出为什么div渲染到300px,那么它也将修复重新渲染,因为它将基于其子元素。
似乎问题也可能出在SVG本身。 我还没有在SVG上定义宽度和高度属性,而是在CSS上这样做了。 如果我在调整大小时操纵SVG宽度属性,它似乎可能有效,但我仍然不清楚为什么SVG的宽度不计算然后适合div。
To my understanding, if a div's width and height properties are not defined, the Parent div will equal the result of the arranged children elements width and height properties added collectively (and respectively).
My current set up is like so:
<div> //container <div> //list of each element <div> // element 1 ... children comprised of on SVG and a few other divs </div> <div> // element 2 ... children comprised of on SVG and a few other divs </div> <div> // element 3 ... children comprised of on SVG and a few other divs </div> …etc… </div> </div>
My problem is that the
width
s of the element divs are not getting set (or updated) correctly. The width of the div should be the width of the child SVG (as it is the widest), and the height of the div should be the height of the child divs (2 of them) and the height of the SVG.Here is the fiddle of the example. You will notice that the bar example is being cut off. This div's computed width is 300, despite its SVG is larger (drag to see the remaining portion)
JQ-UI is in play, so after a user manipulates the size of on representation, the others will re-render themselves. If we can figure out why the div is rendering to 300px, then it will also fix the re-rendering, since it will be based on its children elements.
It appears that the issue might also be with the SVGs themselves. I have not defined the width and height properties on the SVG, rather I did so on the CSS. If I manipulate the SVG width propertuy on resize, it appears to potentially work, but I am still uynsure of why the SVG's width is not calcualated and then fit into the div.
原文:https://stackoverflow.com/questions/18494367
最满意答案
最有效的内存方式是将值存储为json数组,然后拆分键,以便使用ziplist编码的哈希值存储它们。
- 使用say json数组对数据进行编码,因此您有key = value对,如
user:1234567 -> [21,'25-05-2012','14-06-2010']
。- 将您的键分成两部分,这样第二部分就有大约100种可能性。 例如,
user:12345
和67
- 将此组合键存储在像此
hset user:12345 67 <json>
的哈希中hset user:12345 67 <json>
- 要检索用户ID 9876523的用户详细信息,只需执行
hget user:98765 23
并解析json数组- 确保调整设置hash-max-ziplist-entries和hash-max-ziplist-value
Instagram写了一篇很棒的博客文章来解释这种技术 ,所以我将跳过解释为什么这是内存效率的。
相反,我可以告诉你这种技术的缺点。
- 您无法访问或更新用户的单个属性; 你必须重写整个记录。
- 即使您只关心某些字段,也必须始终获取整个json对象。
- 最后,您必须在拆分键上编写此逻辑,这是添加的维护。
与往常一样,这是一种权衡。 确定您的访问模式,看看这样的结构是否有意义。 如果没有,你必须购买更多的内存。
The most memory efficient way is storing values as a json array, and splitting your keys such that you can store them using a ziplist encoded hash.
- Encode your data using say json array, so you have key=value pairs like
user:1234567 -> [21,'25-05-2012','14-06-2010']
.- Split your keys into two parts, such that the second part has about 100 possibilities. For example,
user:12345
and67
- Store this combined key in a hash like this
hset user:12345 67 <json>
- To retrieve user details for user id 9876523, simply do
hget user:98765 23
and parse the json array- Make sure to adjust the settings hash-max-ziplist-entries and hash-max-ziplist-value
Instagram wrote a great blog post explaining this technique, so I will skip explaining why this is memory efficient.
Instead, I can tell you the disadvantages of this technique.
- You cannot access or update a single attribute on a user; you have to rewrite the entire record.
- You'd have to fetch the entire json object always even if you only care about some fields.
- Finally, you have to write this logic on splitting keys, which is added maintenance.
As always, this is a trade-off. Identify your access patterns and see if such a structure makes sense. If not, you'd have to buy more memory.
相关问答
更多-
Redis为了记忆而流产(Redis aborting for OUT OF MEMORY)[2023-01-15]
结果是一个非常有趣和令人惊讶的问题! 其真正原因是它们正在使用的分配器中的内存碎片( dlmalloc )。 希望MSFT能够做得更好,但我希望这需要一些时间。 与此同时,解决方法。 正确的解决方法(暂时) 配置maxmemory和maxheap参数。 使maxheap比maxmemory 。 因此,如果你想要maxmemory=100MB那么使maxheap 5倍甚至10倍,例如maxheap=500MB甚至maxheap=1000MB 。 我不认为有一个很好的经验法则需要多大的maxheap ,这就是为 ... -
Java中的内存效率(Memory Efficiency in Java)[2022-04-26]
没有区别。 编译器会优化内存使用方面的任何潜在差异。 如果你编译(使用javap -c )这两个例子并比较字节码,你会发现字节码是一样的。 当然,这取决于JVM版本。 但是由于这个例子非常微不足道,所以假设两者都不比另一个更有效率。 例1: 码: public class example1 { public static void main(String[] args) { for (int i=0; i<10; i++) { Object a = new O ... -
什么是MySQL“关键效率”(What is MySQL “Key Efficiency”)[2021-05-21]
“关键效率”表示您从MySQL内存中保存的索引缓存获得的价值。 如果您的关键效率很高,那么MySQL通常会从内存空间执行关键查找,这比从磁盘检索相关的索引块要快得多。 提高关键效率的方法是将更多的系统内存用于MySQL的索引缓存。 这样做取决于您使用的存储引擎。 对于MyISAM,增加key-buffer-size的值。 对于InnoDB,增加innodb-buffer-pool-size的值。 然而,正如Michael Eakins指出的那样,操作系统还拥有最近访问的磁盘块缓存。 您的操作系统可用的内存越 ... -
Redis字符串与Redis哈希表示JSON:效率?(Redis strings vs Redis hashes to represent JSON: efficiency?)[2022-07-17]
这取决于您如何访问数据: 选择1: 如果您在大多数访问中使用大多数字段。 如果可能的键有差异 选择方案2: 如果您在大多数访问中只使用单个字段。 如果您总是知道哪些字段可用 PS:作为一个大拇指的规则,去大部分用例需要更少的查询选项。 It depends on how you access the data: Go for Option 1: If you use most of the fields on most of your accesses. If there is variance on po ... -
Lambdas和Procs有几处不同之处。 兰姆达斯有所谓的“小小回报”。 这意味着Lambda会将流程返回给调用它的函数,而Proc将返回调用它的函数。 def proc_demo Proc.new { return "return value from Proc" }.call "return value from method" end def lambda_demo lambda { return "return value from lambda" }.call "return ...
-
redis记忆效率(redis memory efficiency)[2024-03-31]
最有效的内存方式是将值存储为json数组,然后拆分键,以便使用ziplist编码的哈希值存储它们。 使用say json数组对数据进行编码,因此您有key = value对,如user:1234567 -> [21,'25-05-2012','14-06-2010'] 。 将您的键分成两部分,这样第二部分就有大约100种可能性。 例如, user:12345和67 将此组合键存储在像此hset user:12345 67的哈希中hset user:12345 67 要检索用户ID ... -
每个Dictionary都有一些相关的开销:几个int和一些对象引用,即使它是空的,然后一旦你开始添加项目,它就需要两倍的空间。 我假设ConcurrentDictionary几乎是一样的。 因此,不要在每个Point上放置一个新的ConcurrentDictionary,您可能想要尝试使用一个单一的ConcurrentDictionary,这个ConcurrentDictionary不管是使用点数组索引还是正在使用的键。 C#7的新元组语法应该很容易做到。 Each Dictionary tends to ...
-
屏幕刮擦效率(Screen Scraping Efficiency)[2023-03-26]
无论如何你将是IO绑定,你的代码的性能根本不重要(除非你是一个非常糟糕的程序员..) You will be IO bound anyway, the performance of your code won't matter at all (unless you're a really bad programmer..) -
hGetContents返回的String与任何其他Haskell字符串没有区别。 通常,除非程序员采取额外步骤来确保它(例如seq , deepseq ,bang模式),否则不会对Haskell数据进行全面评估。 字符串被定义为(基本上) data List a = Nil | Cons a (List a) -- Nil === [], Cons === : type String = List Char 这意味着字符串是空的,或者是单个字符(头部)和另一个字符串(尾部)。 由于懒惰 ,尾巴可能不存在 ...
-
If语句中的内存效率(Memory efficiency in If statements)[2021-10-01]
if快或慢的主要问题是可预测性。 现代CPU(2000年以后的任何东西)都使用一种称为分支预测的机制 。 首先阅读上面的链接,然后在下面阅读... 哪个更快? if语句构成一个分支,因为CPU需要决定是否跟随或跳过if部分。 如果它正确猜测分支,则跳转将在0或1个周期(1Ghz计算机上1纳秒)内执行。 如果它没有正确地猜测分支,则跳跃将花费50个周期(给予或接受)(微秒的1/200)。 因此,即使将这些差异视为人类,您也需要执行数百万次的if语句。 上述两个陈述可能会在完全相同的时间内执行,因为: 为变量赋 ...