Tags:

มีcode 2 แบบ อยากรู้ว่ามีข้อดีข้อเสียต่างกันอย่างไรครับ
และ แบบ A ใช้ memory เปลืองกว่าแบบมีนัยสําคัญไหมครับ

แบบA
Font font = getFont();
a.setFont(font);

แบบB
a.setFont(getFont());

ขอบคุณครับ

Get latest news from Blognone
By: nat3738
ContributorAndroidRed HatUbuntu
on 18 October 2014 - 14:04 #755062

ไม่ต่างกันครับ

By: tekkasit
ContributorAndroidWindowsIn Love
on 18 October 2014 - 14:36 #755077
tekkasit's picture

อยากรู้ก็ต้อง decompile ดูครับ แต่สองแบบนี้ ถ้าโค้ดมีแค่นี้ น่าจะเท่ากันทุกประการเลยครับ

By: revensoft
Windows PhoneWindows
on 18 October 2014 - 16:11 #755089

แบบ A ใช้ตัวแปรเพิ่มอีกตัวหนึ่งซึ่งหาความต่างอะไรไม่ได้ในเชิง Performance หรือ Memory
แต่แบบ A สามารถอ้างอิงค่านั้นๆ ได้อีกครั้ง ทำให้แบบ B เหมาะสำหรับการใช้ครั้งเดียวใน Method ครับ

ถ้าเขียน cil โค๊ดโดยตรงก็น่าจะประมาณนี้

A:
ldloc.s a
call Font ClassName::getFont()
dup
stloc.s font
callvirt instance void ClassName::setFont(Font)

B:
ldloc.s a
call Font ClassName::getFont()
callvirt instance void ClassName::setFont(Font)

By: zerntrinos
ContributorAndroidWindows
on 19 October 2014 - 02:54 #755178
zerntrinos's picture

เข้าใจละครับ ขอบคุณมากครับ


เวลาดูสาวชอบดูสาวขาวๆ Sex Sex เวลาดู Notebook ชอบแบบ"ถึกๆดำๆ"

Twitter : @Zerntrino
G+ : Zerntrino Plus